Colors with textures
What i'm looking to do is draw my polygons with textures AND a color. an example would be when i went everything to be more of a red tint. i draw everything as normal, textures and everything, then i specify the color to be something like glColorf(1.0f, 0.3f, 0.3f)
nv/md.. i found it
float Diffuse[4];
Diffuse[0] = 1.0f;
Duffuse[1] = 0.3f;
Duffuse[2] = 0.3f;
Duffuse[3] = 1.0f;
glMaterialfv(GL_FRONT, GL_DIFFUSE, Diffuse);
is that correct?
float Diffuse[4];
Diffuse[0] = 1.0f;
Duffuse[1] = 0.3f;
Duffuse[2] = 0.3f;
Duffuse[3] = 1.0f;
glMaterialfv(GL_FRONT, GL_DIFFUSE, Diffuse);
is that correct?
Material calculations are only done when lighting is enabled, mind. And about the code, it's fine but the best way is to plug it in and see for yourself [grin]. You might also want to use ambient material.
/edit: I just noticed, you mentioned in your first post that you are setting the color after you draw everything? Set the color, bind the texture, and draw. You will have nice tinted textures (this is when lighting is not enabled of course, if it is use material properties).
/edit: I just noticed, you mentioned in your first post that you are setting the color after you draw everything? Set the color, bind the texture, and draw. You will have nice tinted textures (this is when lighting is not enabled of course, if it is use material properties).
so should i use diffuse and ambient material? if so, should i set them to the same color value? Say i want the sprite to be partially trasparent. set the color to say 1.0, 1.0f, 1.0f, 0.5f. then set the material's diffuse and ambient to the same? what about lighting? should i just have one directional like source going perpendicular to the faces of the sprites? (this is a 2d environment)
would this be correct? i can't test it because i'm redoing my whole engine and i'm doing one part at a time :)
[source lang=c++] // Position sprite glLoadIdentity(); glScalef(Pos->ScaleX, Pos->ScaleY, 1.0f); glRotatef(Pos->Radian, 0.0f, 0.0f, 1.0f); glTranslatef(PosX, PosY, -PosZ); // Set the colo glColor4f(m_fDiffuse[0], m_fDiffuse[1], m_fDiffuse[2], m_fDiffuse[3]); glMaterialfv(GL_FRONT, GL_DIFFUSE, m_fDiffuse); glMaterialfv(GL_FRONT, GL_AMBIENT, m_fDiffuse); // Bind the texture if there is one if (m_pTexture == NULL) glBindTexture(GL_TEXTURE_2D, NULL); else glBindTexture(GL_TEXTURE_2D, m_pTexture->GetTextureData()); // Draw sprite glBegin(GL_QUADS); { // Top-left glTexCoord2d(m_FrameSrcRect.left * 1.0f / m_pTexture->GetWidth(), m_FrameSrcRect.top * 1.0f / m_pTexture->GetHeight()); glVertex3f(m_lFrameWidth * -0.5f, m_lFrameHeight * 0.5f, 0.0f); // Top-right glTexCoord2d(m_FrameSrcRect.right * 1.0f / m_pTexture->GetWidth(), m_FrameSrcRect.top * 1.0f / m_pTexture->GetHeight()); glVertex3f(m_lFrameWidth * 0.5f, m_lFrameHeight * 0.5f, 0.0f); // Bottom-right glTexCoord2d(m_FrameSrcRect.right * 1.0f / m_pTexture->GetWidth(), m_FrameSrcRect.bottom * 1.0f / m_pTexture->GetHeight()); glVertex3f(m_lFrameWidth * 0.5f, m_lFrameHeight * -0.5f, 0.0f); // Bottom-left glTexCoord2d(m_FrameSrcRect.left * 1.0f / m_pTexture->GetWidth(), m_FrameSrcRect.bottom * 1.0f / m_pTexture->GetHeight()); glVertex3f(m_lFrameWidth * -0.5f, m_lFrameHeight * -0.5f, 0.0f); } glEnd();
Hmm I think it is possible, but blending needs to be turned on.
an example:
Most parts are taken straight from my particle engine.
an example:
glBindTexture(GL_TEXTURE_2D, textureId );glEnable(GL_TEXTURE_2D);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA ,GL_ONE); //CHANGE COLOR glColor4f(particle->color[0], particle->color[1], particle->color[2], particle->color[3]); glBegin(GL_QUADS); glTexCoord2f( 1.0f , 0.0f ); glVertex3f(-size, size, 0.0f ); glTexCoord2f( 1.0f , 1.0f ); glVertex3f( size, size, 0.0f ); glTexCoord2f( 0.0f , 1.0f ); glVertex3f( size,-size, 0.0f ); glTexCoord2f( 0.0f , 0.0f ); glVertex3f(-size,-size, 0.0f ); glEnd();glDisable(GL_BLEND);glDisable(GL_TEXTURE_2D);
Most parts are taken straight from my particle engine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement