PDA

View Full Version : Texture image one color



jqweezy
03-03-2008, 01:24 PM
hello,

I've read in a texture from a bmp file and applied it to a circle. This works fine. Now, when I create a triangle primitive, with a color other than white, it changes the color of my texture to that of the color of the triangle. Why is this? Can anyone help?

Regards,
JQ

-NiCo-
03-03-2008, 01:28 PM
By default the texture env mode is set the GL_MODULATE which means that the color you specify gets modulated by the value fetched from the texture. You can set it to replace by using the following line of code:

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE)

jqweezy
03-03-2008, 02:02 PM
Thanks for your help. I added the line of code you said, however i used glTexEnvf instead because I'm using openGL ES 1.0. So now the texture keeps its proper image and is fine, however, now I can't change the triangle primitive color. The triangle is always white. Can you think of anything else I might be doing wrong?

-NiCo-
03-03-2008, 02:28 PM
Can you post your rendering code?

jqweezy
03-03-2008, 02:52 PM
InitView(){
glClearColor(0, 0, 0, 255);

// Enables texturing
glEnable(GL_TEXTURE_2D);

// Loads the textures.
if(!PVRTLoadTextureFromPointer((void*)tex_base, texName))
{
PVRShellSet(prefExitMessage, "ERROR: Cannot load the texture\n");
return false;
}

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
}

RenderScene(){
glClear(GL_COLOR_BUFFER_BIT);

VERTTYPE afVertices[] = {0.25f,0.0f,0.0f,
0.75f,0.0f,0.0f,
0.75f,0.5f,0.0f,
0.25f,0.5f,0.0f};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,afVertices);

VERTTYPE afColors[] = { 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f };
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4,GL_FLOAT,0,afColors);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

CreateCircle(0.5f, -0.5f, 0.0f, texName);
}

//create filled circle
void CreateCircle(GLfloat radius, GLfloat xpos, GLfloat ypos, GLuint texName){
glBindTexture(GL_TEXTURE_2D, texName);

GLfloat afVertices[FAN_VERTICES*3];
GLfloat angle = 0.0f;

afVertices[0] = xpos;
afVertices[1] = ypos;
afVertices[2] = 0.0f;
for(int i = 3; i<(FAN_VERTICES*3); i++){
afVertices[i++] = (radius*cos(angle) + xpos)*RATIO;
afVertices[i++] = radius*sin(angle) + ypos;
//afVertices[i++] = radius*sin(angle) + ypos;
afVertices[i] = 0.0f;
angle+=(PI/180);
}

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,afVertices);

//pass the texture coordinates
GLfloat pfTexCoord[2*FAN_VERTICES];
angle = 0.0f;
pfTexCoord[0] = 0.5f;
pfTexCoord[1] = 0.5f;
for(int i=2; i<(2*FAN_VERTICES); i++){
pfTexCoord[i++] = 0.5f * cos(angle) + 0.5f;
pfTexCoord[i] = 0.5f * sin(angle) + 0.5f;
angle += (PI/180.0f);
}
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,0,pfTexCoord);

glDrawArrays(GL_TRIANGLE_FAN, 0, FAN_VERTICES);
}


okay,
like i said earlier, the texture mapping works. the cirlce is created with the texture i want. then i create a square in RenderScene(). now the square is suppose to be red, however, it seems like it somewhat looks like the texture that is read into the cirlce (earlier I said it was initially white, its not).

-NiCo-
03-03-2008, 03:23 PM
Ah, I see. Well, if you want something to be textured, you call glEnable(GL_TEXTURE_2D); before the drawing calls and if you don't want it to be textured you have to call glDisable(GL_TEXTURE_2D); before the drawing calls.

jqweezy
03-03-2008, 03:30 PM
Excellent! Thanks for your help. That worked.

Regards,
JQ