OpenGL (1.2 - 2.0) Code Samples - Page 10

Simple Vertex Shader (Cg)
 

Demonstrates how to write a simple vertex shader, or vertex program using Cg. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: cgGLIsProfileSupported, cgCreateContext, cgCreateProgramFromFile, cgGLLoadProgram, cgGetNamedParameter, cgGLSetStateMatrixParameter, cgGLSetParameter4fv, cgGLBindProgram, cgGLEnableProfile, cgGLDisableProfile, cgDestroyProgram, cgDestroyContext, CGprofile, CGcontext, CGprogram, CGparameter, CG_PROFILE_ARBVP1, CG_PROFILE_VP30, CG_PROFILE_VP20, CG_SOURCE, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY, POSITION, COLOR0, main, float4, float3, uniform, float4x4, mul, in, and out.

 

Simple Vertex Shader (CgFX)
 

Demonstrates how to write a simple vertex shader, or vertex program using Cg and Direct3D's FX file format. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: ICgFXEffect, CgFXPARAMETER_DESC, CgFXCreateEffectFromFileA, CgFXSetDevice, CgFXEFFECT_DESC, GetDesc, GetParameterDesc, SetTechnique, Validate, CgFXFreeDevice, CgFXRelease, SetMatrix, SetTexture, and CgFX.

 

Simple Vertex & Pixel Shader (Cg)
 

Demonstrates how to write both a simple vertex and pixel shader using Cg. The two shaders have matching connectors and can be used simultaneously on the same piece of geometry. The shaders in this sample don't really do anything useful or neat, it's meant to be used as a framework or starting place for experimenting with shaders. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

 

Multi-Texturing with Cg
 

This sample demonstrates how to blend two textures together with Cg using either OpenGL's native multi-texture support (using semantics) or by using Cg's special texture functions: cgGLSetTextureParameter, cgGLEnableTextureParameter, and cgGLDisableTextureParameter.

Relevant Keywords: GL_ARB_multitexture, glActiveTextureARB, glMultiTexCoord2fARB, glClientActiveTextureARB, glTexEnvi, glVertex3f, wglGetProcAddress, glGetString, auxDIBImageLoad, glGenTextures, glBindTexture, glTexParameteri, glTexImage2D, glEnable, glDisable, glBindTexture, AUX_RGBImageRec, GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE, GL_ADD, GL_TEXTURE0_ARB, GL_TEXTURE1_ARB, GL_EXTENSIONS, GL_BLEND, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_UNSIGNED_BYTE, PFNGLACTIVETEXTUREARBPROC, PFNGLMULTITEXCOORD2FARBPROC, PFNGLCLIENTACTIVETEXTUREARBPROC, cgGLSetTextureParameter, cgGLEnableTextureParameter, and cgGLDisableTextureParameter.

 

Simple Vertex & Fragment Shader (GLslang)
 

This sample demonstrates how to write vertex and fragment shaders using OpenGL's new high-level shading language GLslang.

Relevant Keywords: wglGetProcAddress, PFNGLCREATEPROGRAMOBJECTARBPROC, PFNGLDELETEOBJECTARBPROC, PFNGLUSEPROGRAMOBJECTARBPROC, PFNGLCREATESHADEROBJECTARBPROC, PFNGLSHADERSOURCEARBPROC, PFNGLCOMPILESHADERARBPROC, PFNGLGETOBJECTPARAMETERIVARBPROC, PFNGLATTACHOBJECTARBPROC, PFNGLGETINFOLOGARBPROC, PFNGLLINKPROGRAMARBPROC, PFNGLGETUNIFORMLOCATIONARBPROC, PFNGLUNIFORM4FARBPROC, PFNGLUNIFORM1IARBPROC, glCreateProgramObjectARB, glDeleteObjectARB, glUseProgramObjectARB, glCreateShaderObjectARB, glShaderSourceARB, glCompileShaderARB, glGetObjectParameterivARB, glAttachObjectARB, glGetInfoLogARB, glLinkProgramARB, glGetUniformLocationARB, glUniform4fARB, glUniform1iARB, GL_VERTEX_SHADER_ARB, GL_FRAGMENT_SHADER_ARB, GL_OBJECT_COMPILE_STATUS_ARB, GL_OBJECT_LINK_STATUS_ARB, GLhandleARB, uniform sampler2D, varying vec2, varying vec4, gl_FragColor, gl_Position, gl_ModelViewProjectionMatrix, gl_Vertex, gl_Color, gl_TexCoord, gl_FragColor, and gl_MultiTexCoord0.