OpenGL Application Framework

xiaoxiao2021-03-06  76

I have been trying to find the general framework for OpenGL applications. With this template, you can create OpenGL applications as you can create Dialog-Based, SDI, and MDI applications in MFC. Here is some of my experiences in this area. I use OpenGL GLUT as an example: the entire application should include the following functions: init (): OpenGL is a state machine, staying throughout the rendering process The status should be set here. You should also set up window systems if needed. Rendering (): Rendering function, this function is based on the core of the entire program. Reshape (): Call the size of the window. When the window is not a full-screen state, the change in the window should call this function. The relevant parameters of the vision and projection should be adjusted according to the size of the window.

Typical Reshape () function is as follows: void Reshape (int width, int height) {glViewport (0,0, width, height); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (45.0f, (GLfloat) width / (GLfloat HEIGHT, 0.5F, 150.0F); GLmatrixMode (GL_ModelView); GLLoadIdentity ();} In FAQ in OpenGL's official website, a framework is also proposed: Program_EntryPoint {// determine Which Depth or Pixel Format Should Be Used. // Create a window with the desired format. // Create a rendering context and make it current with the window. // Set up initial OpenGL state. // Set up callback routines for window resize and window refresh.} handle_resize {glViewport ( ...); glMatrixMode (GL_PROJECTION); glLoadIdentity (); // Set projection transform with glOrtho, glFrustum, gluOrtho2D, gluPerspective, etc.} handle_refresh {glClear (...); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); / / Set view transform with glulookat or equivalent // for Each Object (i) in The Scene That Needs to Be Rendered: // Push Relevant STA cks, eg, glPushMatrix, glPushAttrib. // Set OpenGL state specific to object (i). // Set model transform for object (i) using glTranslatef, glScalef, glRotatef, and / or equivalent. // Issue rendering commands for object ( i). // POP Relevant Stacks, (EG, GLPOPMATRIX, GLPOPATTRIB.) // end for loop. // swap buffers.} The officially specified framework and the frame of my analysis are almost the same :) Reference: 1. http://www.opengl.org/resources/faq/technical/gettingstarted.htm# Gett0008 ------------------------ ----- Committed to multimedia technology, becoming a thoughtful software engineer ------------------------ This article is my original creation, to reprint Please contact your own or indicate. Welcome everyone to make valuable comments on the content of the article, and I hope that everyone will point out the mistakes in the text, so I can correct it in time.

转载请注明原文地址:https://www.9cbs.com/read-108489.html

New Post(0)