|
It is possible to mix 'raw' OpenGL calls with the G3D rendering engine. This can give more flexibility in the rendering cycle, or be used to acheive different effects.
There is one major limitation when using raw OpenGL with G3D:
The G3D RenderDevice keeps track of the current OpenGL state, because of this, OpenGL must be restored to the state in which it started. This is especially important when dealing with OpenGL shaders.
Failing to return the state to that expected by RenderDevice may cause either unexpected behaviour, or a program crash.
While using raw OpenGL calls may be faster than using the equivalent G3D methods, RenderDevice will usually optimise state calls, meaning that a sequence of RenderDevice calls will probably end up being faster than the equivalent OpenGL.
When using Vertex Arrays (VAR), the overhead of calls is negligible as a single call can draw many polygons.
The benefit of mixing raw OpenGL with the G3D renderer is to enable effects that aren't directly supported by G3D.
In particular, fog and TextureCoordinate generation are not supported as renderer method as G3D believes that shaders are a better method of handling these calls. However, if OpenGL fog support is explicitly needed, this can be done using a raw OpenGL command with the RenderDevice. Another case of this is glDepthRange.
Also, underlying OpenGL handles can be gained from the Texture and FrameBuffer objects and bound manually, if this is advantageous to your code.
Finally, the raw OpenGL commands can be used to load OpenGL extensions, for an example of this code, see the GLCaps code for an example of this.
OpenGL handles can be retrieved out of most G3D objects, including Texture and Framebuffer (Texture::openGLID and FrameBuffer::openglid). Also, many G3D objects can be created out of an OpenGL handle, again including Texture (Texture::fromGL).
G3D does provide a series of helper functions if you wish to use raw OpenGL with G3D. These bridge between G3D data types and OpenGL functions. Examples of these include glVertex(Vector3) and glGetInteger.
To debug raw OpenGL, use getOpenGLState, debugAssertGLOk and glEnumToString.
A simple code example using raw OpenGL vertex calls to draw a primitive shape:
renderDevice->pushState();
renderDevice->beforePrimitive();
glPushMatrix();
glRenderMode(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(2.0f, 0.0f, 0.0f);
glPopMatrix();
renderDevice->afterPrimitive();
renderDevice->popState();
Generated on Thu Aug 2 11:40:43 2007 for G3D by
1.5.2
Hosted by
|