Jump to content
  • Advertisement
Sign in to follow this  
Phantom5800

Texturing question (probably trivial)

This topic is 2592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my first time writing a graphics engine and I have run in to something that doesn't make sense to me. I am able to load textures into my resource manager just fine, but when I try to do some drawing tests I get incorrect results when attempting to draw two separate textures.

After binding the first texture, I draw a quad using glBegin/glEnd (I know, bad, but I'm just starting this and wanted to test my texture loading before going further), then I do the same for the second. However, both quads are drawn with the second texture.

Here is the relevant code (if you need to see my texture loading code as well, I can post that, but I am pretty sure I am just doing something stupid here):


Texture_GL *tex1 = dynamic_cast<Texture_GL*>(g_resources->GetResource("sample1.png"));
if (tex1)
{
glBindTexture(GL_TEXTURE0, tex1->m_glid);
std::cout << "Bound sample1.png, id = " << tex1->m_glid << std::endl;
}

glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.0f);

glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);

glTexCoord2f(0.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();

Texture_GL *barry = dynamic_cast<Texture_GL*>(g_resources->GetResource("Barry.png"));
if (barry)
{
glBindTexture(GL_TEXTURE0, barry->m_glid);
std::cout << "Bound Barry.png, id = " << barry->m_glid << std::endl;
}

glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-0.5f, 0.0f, -1.0f);

glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.5f, 0.0f, -1.0f);

glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.5f, 1.0f, -1.0f);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, 1.0f, -1.0f);
glEnd();


EDIT: I attached a couple screenshots. The first one (Sample.png) shows what I expected to see, with just binding the first texture and not overwriting it. The second screenshot (Barry.png) shows what it looks like using the above code

Share this post


Link to post
Share on other sites
Advertisement
So put:


sigh = true;
barry = true;
if (sigh)
{
glBindTexture(GL_TEXTURE0, tex1->m_glid);
std::cout << "Bound sample1.png, id = " << tex1->m_glid << std::endl;
}


Your variable sigh is not true. That's all.

Share this post


Link to post
Share on other sites

Your variable sigh is not true. That's all.

lol sorry, that should have said tex1, but that isn't the problem, that was just a typo when I was changing variable names (there isn't actually a variable called sigh).

And yes, they are both true every frame.

Share this post


Link to post
Share on other sites
Actually your problem is:

glBindTexture(GL_TEXTURE0, <----------its GL_TEXTURE_2D, index_of_image)

glActiveTexture(GL_TEXTURE0...GL_TEXTURE1..GL_TEXTURE2) you can activate multiple textures, google glBindTexture for what you can put as the first parameter.

Share this post


Link to post
Share on other sites

Actually your problem is:

glBindTexture(GL_TEXTURE0, <----------its GL_TEXTURE_2D, index_of_image)

glActiveTexture(GL_TEXTURE0...GL_TEXTURE1..GL_TEXTURE2) you can activate multiple textures, google glBindTexture for what you can put as the first parameter.


herp derp, that's right. Thank you. I remember this from a graphics assignment now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!