Colors with textures

Started by
16 comments, last by AIRmichael 18 years, 3 months ago
I set the blend when OGL is initialized.. but i have a question. when i don't wanna use a texture, should i just disable textures? or bind a NULL texture?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Advertisement
disable.
Binding 0 ISNT the same, it binds a proxy texture which may or may not do as you expect.

Side note and tip: Only enable blending for things you need blended, turning it off for objects which dont need to blend with the frame buffer improves your speed as it cuts down on framebuffer traffic.
alright, will do. so should i just have the texture be disabled and only have them enabled when needed?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
well, the correct way depends on what you are doing, if you are doing alot of texture'd objects then enable it and only disable for non-textured stuff, reverse if otherwise
Hi, Evil! I'll comment parts of your code:

Quote:
// Set the color
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);

You don't need all this material stuff for now. Please, continue reading...

Quote:
// Bind the texture if there is one
if (m_pTexture == NULL)
glBindTexture(GL_TEXTURE_2D, NULL);
else
glBindTexture(GL_TEXTURE_2D, m_pTexture->GetTextureData());
Don't do that (unexpected results). Prefer:
if ( m_pTexture ) {  // Note that the method's name "GetTextureData" is a bit confusing. Prefer      // something like "GetId()" or "GetName()" (yes, "name", OpenGL ARB uses this   // all the time).  glBindTexture( GL_TEXTURE_2D, m_pTexture->GetName() );  // Draw quads  ...}


Quote:
// 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);

Have you noted that, if "m_pTexture" doesnt't exist, this piece of code would crash your application? You can't call any method from a NULL pointer... And you don't need a "{" after "glBegin(GL_QUADS)", neither before the "glEnd()" call.


Finally, from what I had understood, what you want is just:
if ( m_pTexture ) {  // 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 color (this is enough to get the "red tint" effect you're asking for.  // Just play around with the alpha value "color[3]" for adjustments  glColor4f( color[0], color[1], color[2], color[3]);  glBindTexture( GL_TEXTURE_2D, m_pTexture->GetName() );	// Supposing GL_TEXTURE_2D is already enabled  // 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();}


And remember, everything depends on what you are doing / want to do, so my code could be plainly wrong...

Goodbye and good luck!
I use glTexEnv(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
After that you could just use glColor3F.
where would that be used and what does it do?
-------------------------Unless specified otherwise, my questions pertain:Windows Platform (with the mindset to keep things multi-platform as possible)C++Visual Studio 2008OpenGL with SFML
Quote:Original post by EvilKnuckles666
where would that be used and what does it do?


Right after or right before binding the texture. Not sure if that matters.

It combines the texture and gl color.

This topic is closed to new replies.

Advertisement