OpenGL (1.2 - 2.0) Code Samples - Page 9

Optimized Sphere
 

Renders a sphere using either a triangle list or a combination of tri-strips and tri-fans for benchmarking purposes.

 

Benchmarking Test App
 

Renders a textured sphere using either Immediate Mode calls, Immediate Mode calls cached in a Display List, or a Vertex Array for benchmarking purposes.

  • Download (Visual Studio project - Last Updated: 10/13/05)
  • Download (Linux - Last Updated: 02/10/05)

 

Using Textured Animated Sprites As Overlays
 

It may sound strange to write 3D code that mimics the traditional sprite animation found in 2D games, but many modern video card drivers place little emphasis on 2D bit-blitting anymore. This means that 3D sprites, which perform 2D style animation through the manipulation of texture coordinates, are much faster because they can take advantage of any hardware acceleration that exists in the hardware’s TN&L pipeline.

  • Download (Visual Studio project - Last Updated: 04/28/05)
  • Download (Linux - Last Updated: 02/10/05)

 

Simple Vertex Shaders
 

The following code samples demonstrate how to write a simple vertex shader using the various OpenGL extensions currently available. Of course, writing shaders using GPU assembly will soon be replaced by either OpenGL 2.0's implementation of a high-level shader language or Cg (C for graphics) from nVIDIA. Check out the DirectX9 source code page for the Direct3D equivalent of these samples.

Relevant Keywords: GL_NV_vertex_program, GL_EXT_vertex_shader, glGenProgramsNV, glDeleteProgramsNV, glBindProgramNV, glLoadProgramNV, glProgramParameter4fNV, glTrackMatrixNV, glBindParameterEXT, glGenVertexShadersEXT, glBindVertexShaderEXT, glBeginVertexShaderEXT, glGenSymbolsEXT, glShaderOp2EXT, glShaderOp1EXT, glEndVertexShaderEXT, glSetInvariantEXT, glSetLocalConstantEXT, glGetString, wglGetProcAddress, GL_VERTEX_PROGRAM_NV, GL_VERTEX_SHADER_EXT, GL_MODELVIEW_PROJECTION_NV, GL_IDENTITY_NV, GL_MODELVIEW_MATRIX, GL_PROJECTION_MATRIX, GL_CURRENT_VERTEX_EXT, GL_CURRENT_COLOR, GL_VECTOR_EXT, GL_LOCAL_CONSTANT_EXT, GL_FULL_RANGE_EXT, GL_FLOAT, GL_LOCAL_EXT, GL_OP_MULTIPLY_MATRIX_EXT, GL_OUTPUT_VERTEX_EXT, GL_OP_MOV_EXT, GL_OUTPUT_COLOR0_EXT, PFNGLGENPROGRAMSNVPROC, PFNGLDELETEPROGRAMSNVPROC, PFNGLBINDPROGRAMNVPROC, PFNGLLOADPROGRAMNVPROC, PFNGLPROGRAMPARAMETER4FNVPROC, PFNGLTRACKMATRIXNVPROC, PFNGLBINDPARAMETEREXTPROC, PFNGLGENVERTEXSHADERSEXTPROC, PFNGLBINDVERTEXSHADEREXTPROC, PFNGLBEGINVERTEXSHADEREXTPROC, PFNGLGENSYMBOLSEXTPROC, PFNGLSHADEROP2EXTPROC, PFNGLSHADEROP1EXTPROC, PFNGLENDVERTEXSHADEREXTPROC, PFNGLSETINVARIANTEXTPROC, PFNGLSETLOCALCONSTANTEXTPROC, !!VP1.1, DP4, HPOS, OPOS, MOV, , COL0, and END. *

(*This list doesn't include the keywords for the ARB_vertex_program extension since they've already leen listed below.)

 

 

Simple ARB Vertex & Pixel Shader
 

Demonstrates how to write both a simple vertex and pixel shader using OpenGL's new extensions, ARB_vertex_program, and ARB_fragment_program. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: GL_ARB_vertex_program, GL_ARB_fragment_program, glGenProgramsARB, glDeleteProgramsARB, glBindProgramARB, glProgramStringARB, glProgramEnvParameter4fARB, glGetString, wglGetProcAddress, GL_VERTEX_PROGRAM_ARB, GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, GL_C4UB_V3F, GL_QUADS, PFNGLGENPROGRAMSARBPROC, PFNGLDELETEPROGRAMSARBPROC, PFNGLBINDPROGRAMARBPROC, PFNGLPROGRAMSTRINGARBPROC, PFNGLPROGRAMENVPARAMETER4FARBPROC, !!ARBvp1.0, !!ARBfp1.0, PARAM, ATTRIB, OUTPUT, state.matrix.mvp, program.env, vertex.position, vertex.color, result.position, result.color, fragment.texcoord, fragment.color.primary, texture, TEMP, TXP, MUL, ADD, 2D, DP4, MOV, and END.