Reputation: 187
To make a lighting system for a voxel game, I need to specify a darkness value per vertex. I'm using GL_COLOR_MATERIAL
and specifying a color per vertex, like this:
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_QUADS);
glColor3f(0.6f, 0.6f, 0.6f);
glTexCoord2f(...);
glVertex3f(...);
glColor3f(0.3f, 0.3f, 0.3f);
glTexCoord2f(...);
glVertex3f(...);
glColor3f(0.7f, 0.7f, 0.7f);
glTexCoord2f(...);
glVertex3f(...);
glColor3f(0.9f, 0.9f, 0.9f);
glTexCoord2f(...);
glVertex3f(...);
glEnd();
This is working, but with many quads it is very slow. I'm using display lists too. Any good ideas in how to make vertices darker?
Upvotes: 0
Views: 148
Reputation: 162164
You're using immediate mode (glBegin, glEnd and everything in between). If performance is what you need, then I recommend you stop doing that.
What you're probably after is a generic vertex attribute. And lo and behold: Modern OpenGL actually has exactly this: Generic attributes. They even went so far, doing the right thing and do away with the predefined attributes (position, color, normal, texcoords, etc.) and have only generic attributes in OpenGL-3 core and later.
The functions glVertexAttrib (most of the time a Uniform does the job better) and glVertexAttribPointer are your friends. Specify how vertex attributes are processed using an appropriate vertex shader.
Upvotes: 1