public void MakeCurrent() { if (WGL.wglMakeCurrent(this.intptr_1, this.intptr_2) == 0) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
public void Render() { // Render OpenGL contents if (DC == 0 || RC == 0) { return; } WGL.wglMakeCurrent(DC, RC); // Clear buffers and load frame GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glBindTexture(GL.GL_TEXTURE_2D, textureData[2]); camera.applyCamera(); GL.glLoadIdentity(); GL.glDisable(GL.GL_TEXTURE_2D); _sat.Render(); GL.glEnable(GL.GL_TEXTURE_2D); GL.glBindTexture(GL.GL_TEXTURE_2D, textureData[0]); _earth.Render(); // Flush and swap GL.glFlush(); WGL.wglSwapBuffers(DC); }
private void initRenderingContext() { m_uint_RC = WGL.wglCreateContext(m_uint_DC); if (m_uint_RC == 0) { MessageBox.Show("Unable to get rendering context"); return; } if (WGL.wglMakeCurrent(m_uint_DC, m_uint_RC) == 0) { MessageBox.Show("Unable to make rendering context current"); return; } }
/// <summary> /// Override OnPaint to draw our gl scene /// </summary> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { float rot1 = 0, rot2 = 0; if (DC == 0 || RC == 0) { return; } if (lastMs == 0) { lastMs = DateTime.Now.Ticks; } long currentMs = DateTime.Now.Ticks; long milliseconds = (currentMs - lastMs) / 10000; lastMs = currentMs; //Calculate elapsed timer WGL.wglMakeCurrent(DC, RC); GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glLoadIdentity(); GL.glTranslatef(0.0f, 0.0f, -6.0f); // Translate 6 Units Into The Screen GL.glRotatef(angle, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle for (rot1 = 0; rot1 < 2; rot1++) // 2 Passes { GL.glRotatef(90.0f, 0.0f, 1.0f, 0.0f); // Rotate 90 Degrees On The Y-Axis GL.glRotatef(180.0f, 1.0f, 0.0f, 0.0f); // Rotate 180 Degress On The X-Axis for (rot2 = 0; rot2 < 2; rot2++) // 2 Passes { GL.glRotatef(180.0f, 0.0f, 1.0f, 0.0f); // Rotate 180 Degrees On The Y-Axis GL.glBegin(GL.GL_TRIANGLES); // Begin Drawing Triangles GL.glColor3f(1.0f, 0.0f, 0.0f); GL.glVertex3f(0.0f, 1.0f, 0.0f); GL.glColor3f(0.0f, 1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, 1.0f); GL.glColor3f(0.0f, 0.0f, 1.0f); GL.glVertex3f(1.0f, -1.0f, 1.0f); GL.glEnd(); // Done Drawing Triangles } } GL.glFlush(); // Flush The GL Rendering Pipeline WGL.wglSwapBuffers(DC); angle += (float)(milliseconds) / 5.0f; }