protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glClearColor(0.5f, 0.9f, 1.0f, 1.0f); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); //GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_Hint, GL.GL_NICEST); GL.glViewport(0, 0, this.Width, this.Height); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GL.glShadeModel(GL.GL_SMOOTH); GLU.gluPerspective(60, (float)Width / (float)Height, 0.45f, 1000.0f); GenerateTextures(1);////////////////////////////////////// GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); }
protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.m_Width == 0 || this.m_Height == 0) { return; } GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glViewport(0, 0, this.m_Width, this.m_Height); GL.glClearColor(0, 0, 0, 0); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); //1 GLU.gluPerspective(45.0, ((double)m_Width) / m_Height, 1.0, 1000.0); //GLU.gluOrtho2D(0, Width, 0, Height); //the same //GLU.gluOrtho(0, iWidth, 0, iHeight, -1, 1); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); InitTexture(Resources.dreidel); }
protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glViewport(0, 0, Width, Height); GL.glClearColor(0, 0, 0, 0); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); double d = (Width) / Height; GLU.gluPerspective(100.0, (Width) / Height, 1.0, 1000.0); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); InitTexture(); }
protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); GL.glClearDepth(1.0f); GL.glEnable(GL.GL_LIGHT0); GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_Hint, GL.GL_NICEST); GL.glViewport(0, 0, Width, Height); GL.glClearColor(0, 0, 0, 0); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GLU.gluPerspective(45.0, 1.0, 1.0, 1000.0); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedTraslations); InitTexture("SurgeryRoom.bmp"); }
public void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); GL.glClearDepth(1.0f); GL.glEnable(GL.GL_LIGHT0); GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); // GL.GL_AMBIENT_AND_DIFFUSE / GL.GL_SHININESS //GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glViewport(0, 0, this.Width, this.Height); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GLU.gluPerspective(45, ((double)Width) / Height, 1.0, 1000.0); GL.glMatrixMode(GL.GL_MODELVIEW); //save the current MODELVIEW Matrix (now it is Identity) //GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); InitTexture("IMG\\1.bmp"); }
protected virtual void initRenderingGL() { if (m_DeviceContext == 0 || m_RenderingContext == 0) { return; } if (m_DisplayPanel.Width == 0 || m_DisplayPanel.Height == 0) { return; } GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); GL.glClearDepth(1.0f); GL.glClearColor(0.5f, 0.5f, 0.5f, 0.0f); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_Hint, GL.GL_NICEST); GL.glViewport(0, 0, m_DisplayPanel.Width, m_DisplayPanel.Height); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); //nice 3D GLU.gluPerspective(70.0, 1.0, 0.4, 500.0); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); TextureUtills.GenerateTextures(); //save the current MODELVIEW Matrix (now it is Identity) GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); }
protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glClearColor(0.5f, 0.5f, 0.5f, 0.0f); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glViewport(0, 0, this.Width, this.Height); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); //nice 3D GLU.gluPerspective(45.0, 1.0, 0.4, 100.0); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); //save the current MODELVIEW Matrix (now it is Identity) GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); }
/// <summary> /// Event handler called when the form is loaded. It retrieves the controls /// window handle and device context and creates the rendering context. /// </summary> protected virtual void InitializeGL(object sender, EventArgs e) { m_uint_HWND = (uint)this.Handle.ToInt32(); m_uint_DC = WGL.GetDC(m_uint_HWND); // CAUTION: Not doing the following WGL.wglSwapBuffers() on the DC will // result in a failure to subsequently create the RC. WGL.wglSwapBuffers(m_uint_DC); //Get the pixel format WGL.PIXELFORMATDESCRIPTOR pfd = new WGL.PIXELFORMATDESCRIPTOR(); WGL.ZeroPixelDescriptor(ref pfd); pfd.nVersion = 1; pfd.dwFlags = (WGL.PFD_DRAW_TO_WINDOW | WGL.PFD_SUPPORT_OPENGL | WGL.PFD_DOUBLEBUFFER); pfd.iPixelType = (byte)(WGL.PFD_TYPE_RGBA); pfd.cColorBits = 32; pfd.cDepthBits = 32; pfd.iLayerType = (byte)(WGL.PFD_MAIN_PLANE); int pixelFormatIndex = 0; pixelFormatIndex = WGL.ChoosePixelFormat(m_uint_DC, ref pfd); if (pixelFormatIndex == 0) { MessageBox.Show("Unable to retrieve pixel format"); return; } if (WGL.SetPixelFormat(m_uint_DC, pixelFormatIndex, ref pfd) == 0) { MessageBox.Show("Unable to set pixel format"); return; } //Create rendering context 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; } //Set up OpenGL related characteristics ResizeGL(null, null); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); //GL.glEnable(GL.GL_CULL_FACE); GL.glCullFace(GL.GL_BACK); }
protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); GL.glClearDepth(1.0f); GL.glEnable(GL.GL_LIGHT0); GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_Hint, GL.GL_NICEST); GL.glViewport(0, 0, this.Width, this.Height); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); //nice 3D GLU.gluPerspective(45.0, 1.0, 0.4, 100.0); //! TEXTURE 1a GL.glEnable(GL.GL_COLOR_MATERIAL); float[] emis = { 0.3f, 0.3f, 0.3f, 1 }; GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, emis); //! TEXTURE 1a GL.glShadeModel(GL.GL_SMOOTH); GLU.gluPerspective(viewAngle, (float)Width / (float)Height, 0.45f, 30.0f); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); //! TEXTURE 1a GenerateTextures(); //! TEXTURE 1b //save the current MODELVIEW Matrix (now it is Identity) GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); }
public void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glViewport(0, 0, this.Width, this.Height); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); //Z-BUFFER SHOW begin if (!bPerspective) { GL.glOrtho(-4, 4, -4, 4, -4, 4); } else { // - no Grey nuances: differences of our objects Z // are relatively 0 to 100.0f ... 0.45f GLU.gluPerspective(45.0f, Width / Height, 0.45f, 500.0f); } GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); //save the current MODELVIEW Matrix (now it is Identity) GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, AccumulatedRotationsTraslations); Zbuf = new float[Width * Height]; GenerateTextures(); }
protected virtual void initRenderingGL() { if (m_uint_DC == 0 || m_uint_RC == 0) { return; } if (this.Width == 0 || this.Height == 0) { return; } GL.glShadeModel(GL.GL_SMOOTH); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); GL.glClearDepth(1.0f); if (GlobalProperties.LightBeamOn) { GL.glEnable(GL.GL_LIGHT0); } GL.glEnable(GL.GL_COLOR_MATERIAL); GL.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glViewport(0, 0, this.Width, this.Height); GL.glClearColor(0, 0, 0, 0); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); GLU.gluPerspective(90.0, ((double)Width) / Height, 1.0, 1000.0); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); GenerateTextures(); }
// ############################################################################ // ############################################################################ // ############################################################################ // ############################################################################ // ============================================================================ // The following is an example of OpenGL rendering code, complete with // buffer swapping. This function can be called by a Form's "OnPaint()" // method if a previous WGL.DemoInitOpenGL() call (for example) has // already successfully established a valid Render Context (RC). // ============================================================================ public static void DemoOpenGLDraw ( int int_WindowWidth, int int_WindowHeight, uint uint_DC ) { int int_Phase = (int)(System.Environment.TickCount % 120000); float float_Phase = (float)(0.3f * (int_Phase)); if (int_WindowWidth <= 0) { int_WindowWidth = 1; } if (int_WindowHeight <= 0) { int_WindowHeight = 1; } GL.glViewport(0, 0, int_WindowWidth, int_WindowHeight); GL.glEnable(GL.GL_DEPTH_TEST); GL.glDepthFunc(GL.GL_LEQUAL); GL.glEnable(GL.GL_CULL_FACE); GL.glCullFace(GL.GL_BACK); GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); GL.glMatrixMode(GL.GL_PROJECTION); GL.glLoadIdentity(); //GL.glOrtho( 0.0f, (float)(int_WindowWidth), 0.0f, (float)(int_WindowHeight), -1.0f, 1.0f ); GLU.gluPerspective ( 60.0, // Field of view angle (Y angle; degrees) ((double)(int_WindowWidth) / (double)(int_WindowHeight)), 1.0, // Near plane 1000.0 // Far plane ); GL.glMatrixMode(GL.GL_MODELVIEW); GL.glLoadIdentity(); // Translating the camera to +600.0f Z is essentially // adding -600.0f to all drawing commands. GL.glTranslatef(0.0f, 0.0f, -600.0f); GL.glRotatef((0.11f * float_Phase), 1.0f, 0.0f, 0.0f); GL.glRotatef((0.31f * float_Phase), 0.0f, 1.0f, 0.0f); GL.glRotatef((0.19f * float_Phase), 0.0f, 0.0f, 1.0f); float[][] vert_xyz = new float[8][] { new float[] { -100.0f, -100.0f, -100.0f }, // 0 new float[] { -100.0f, -100.0f, 100.0f }, // 1 new float[] { -100.0f, 100.0f, -100.0f }, // 2 new float[] { -100.0f, 100.0f, 100.0f }, // 3 new float[] { 100.0f, -100.0f, -100.0f }, // 4 new float[] { 100.0f, -100.0f, 100.0f }, // 5 new float[] { 100.0f, 100.0f, -100.0f }, // 6 new float[] { 100.0f, 100.0f, 100.0f } // 7 }; int [][] tri_abc = new int [12][] { new int[] { 0, 2, 4 }, new int[] { 4, 2, 6 }, // Back new int[] { 0, 4, 1 }, new int[] { 1, 4, 5 }, // Bottom new int[] { 0, 1, 2 }, new int[] { 2, 1, 3 }, // Left new int[] { 4, 6, 5 }, new int[] { 5, 6, 7 }, // Right new int[] { 2, 3, 6 }, new int[] { 6, 3, 7 }, // Top new int[] { 1, 5, 3 }, new int[] { 3, 5, 7 } // Front }; float[][] colors_rgb = new float[12][] { new float[] { 0.5f, 0.1f, 0.1f }, new float[] { 1.0f, 0.1f, 0.1f }, // Red new float[] { 0.5f, 0.5f, 0.1f }, new float[] { 1.0f, 1.0f, 0.1f }, // Yellow new float[] { 0.1f, 0.5f, 0.1f }, new float[] { 0.1f, 1.0f, 0.1f }, // Green new float[] { 0.1f, 0.5f, 0.5f }, new float[] { 0.1f, 1.0f, 1.0f }, // Cyan new float[] { 0.1f, 0.1f, 0.5f }, new float[] { 0.1f, 0.1f, 1.0f }, // Blue new float[] { 0.5f, 0.1f, 0.5f }, new float[] { 1.0f, 0.1f, 1.0f } // Magenta }; int iTriTotal = 12; int iTriIndex = 0; GL.glBegin(GL.GL_TRIANGLES); for (iTriIndex = 0; iTriIndex < iTriTotal; iTriIndex++) { GL.glColor3fv(colors_rgb[iTriIndex]); GL.glVertex3fv(vert_xyz[tri_abc[iTriIndex][0]]); GL.glColor3fv(colors_rgb[iTriIndex]); GL.glVertex3fv(vert_xyz[tri_abc[iTriIndex][1]]); GL.glColor3fv(colors_rgb[iTriIndex]); GL.glVertex3fv(vert_xyz[tri_abc[iTriIndex][2]]); } GL.glEnd(); WGL.wglSwapBuffers(uint_DC); }