PDA

View Full Version : glColorPointer question



11-27-2005, 11:11 AM
Hello, i want to use the function glColorPointer, but i dont know how to specify what color to use.
I've got this so far
glColorPointer( 4, GL_UNSIGNED_BYTE, 0, &colorRed );

The problem is, is that &colorRed is still an unidentified object. Cause i dont know how to make it point to a color.
Any idea how to do this?

jide
11-27-2005, 11:24 AM
Take a good opengl programming book or at least see good tutorials about gl, check nehe on a search engine for example.

songho
11-28-2005, 07:50 AM
<Fluxx>,
The array of color components can specify the color of each vertex in vertex array. For example, if you have 3 vertices in your vertex array to create a triangle, you will have vertex coords array with 3 of (xyz) elements and color array with 3 of (r,g,b,a) elements. (same number of elements in vertex array)


GLfloat vertices[] = { v1x, v1y, v1z,
v2x, v2y, v2z,
v3x, v3y, v3z };
GLubyte colors[] = { v1r, v1g, v1b, v1a,
v2r, v2g, v2b, v2a,
v3r, v3g, v3b, v3a };If you want to set all vertices to red;

GLubyte colors[] = { 255, 0, 0, 255,
255, 0, 0, 255,
255, 0, 0, 255 };In redering time, you can call glColorPointer() like this;
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
==song==