I use OpenGL and SDL2 to render spine animations. In a specific z-order this animations are disposed like white blocks. All texture get white. I guess this error is in OpenGL draw code.
glPushMatrix();
float texw=0, texh=0;
if (texture) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (SDL_GL_BindTexture(texture, &texw, &texh) != 0)
printf("WTF\n");
}
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(color[0], color[1], color[2], color[3]);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, uvs);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// if (num_vertices > 0) {
glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT, indices);
glDisableClientState(GL_VERTEX_ARRAY);
// glDisableClientState(GL_COLOR_ARRAY);
if (texture) {
SDL_GL_UnbindTexture(texture);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
glColor4f(1.0, 1.0, 1.0, 1.0);
glPopMatrix();
This is my code, some one see something wrong in this code ?
Why i'm getting white textures ?
Two-dimensional texturing has to be enabled by
glEnable(GL_TEXTURE_2D)
and can be disabled byglDisable(GL_TEXTURE_2D)
.If texturing is enables then the texture wich is currently bound when the geometry is drawn is wrapped on the geometry.
If texturing is enabled, then by default the color of the texel is multiplied by the current color, because by default the texture environment mode (
GL_TEXTURE_ENV_MODE
) isGL_MODULATE
. SeeglTexEnv
. This causes that the color of the texels of the texture is "mixed" by the last color which you have set byglColor4f
.Note that all of this only applies in immediate mode if you are not using a shader program.