public void load(string path, string file) { // release old object if (m_current_object != IntPtr.Zero) { NIFAPI.ReleaseObject(m_current_object); } if (mn_gl_list != 0) { GL.glDeleteLists(mn_gl_list, 1); mn_gl_list = 0; } // load new object m_current_object = NIFAPI.CreateObject(path, file); if (m_current_object == IntPtr.Zero) { MessageBox.Show(this, "Error loading object"); } // reset the camera camera.targetObject(m_current_object, CCamera.e_viewPosition.Front); // make sure timer is running timer1.Start(); }
/// <summary> /// the rendering part /// </summary> protected override void OnPaint(PaintEventArgs e) { // Clear The Screen And The Depth Buffer GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // a simple optimation. if (mn_gl_list == 0 && m_current_object != IntPtr.Zero) { GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); mn_gl_list = GL.glGenLists(1); GL.glNewList(mn_gl_list, GL.GL_COMPILE); NIFAPI.Render(m_current_object); GL.glEndList(); } // set up the camera view (loads the matrix) camera.setView(); // add a object rotation if (mb_rotation) { mf_rotation += 0.5f; GL.glRotatef(mf_rotation, 0.0f, 0.0f, 1.0f); } if (mn_gl_list != 0) { GL.glCallList(mn_gl_list); } else { // render the object if (m_current_object != IntPtr.Zero) { NIFAPI.Render(m_current_object); } } // display it GL.wglSwapBuffers(m_hdc); }
public View() { InitializeComponent(); // Initialize NIFAPI NIFAPI.Create(this.Handle); // Get DC handle (you've to release it) m_hdc = GL.GetDC(this.Handle); // Create camera camera = new CCamera(); // init vars last_mouse_position = new Point(0, 0); m_current_object = new IntPtr(0); mf_rotation = 0; mb_rotation = true; mn_gl_list = 0; mb_delta_camera = true; }
public void loadDAOC(int type, int id) { // release old object if (m_current_object != IntPtr.Zero) { NIFAPI.ReleaseObject(m_current_object); } if (mn_gl_list != 0) { GL.glDeleteLists(mn_gl_list, 1); mn_gl_list = 0; } // load new object switch (type) { case 0: m_current_object = DAOCAPI.LoadMonster(id); break; case 1: m_current_object = DAOCAPI.LoadItem(id); break; case 2: m_current_object = DAOCAPI.LoadZone(id); mb_rotation = false; // don't want rotating zone :) break; } ; if (m_current_object == IntPtr.Zero) { MessageBox.Show(this, "Error loading object"); } // reset the camera camera.targetObject(m_current_object, CCamera.e_viewPosition.Right); // make sure timer is running timer1.Start(); }
protected override void Dispose(bool disposing) { // release object if (m_current_object != IntPtr.Zero) { NIFAPI.ReleaseObject(m_current_object); } // release NIFAPI NIFAPI.Release(); // release DC GL.ReleaseDC(this.Handle, m_hdc); if (disposing) { if (components != null) { components.Dispose(); } } base.Dispose(disposing); }
protected override void OnSizeChanged(EventArgs e) { // let the NIFAPI reset the aspect ratio NIFAPI.OnWindowResize(); }