Jump to content
  • Advertisement
Sign in to follow this  
Zuka

Basic texture-mapping using Corona

This topic is 3157 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

Ok, so I'm drawing a basic quad with texture coordinates:
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -5.0f);
glBegin(GL_QUADS);
	glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); 
	glVertex3f(1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); 
	glVertex3f(1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); 
	glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f);
glEnd();
Yeah. I see the quad. It's a white square in the middle of the screen. That's right. So, then I load my texture using Corona like so
Texture2D::Texture2D(string FileName)
{
	Valid = false;
	Filename = FileName;
	corona::Image *img = corona::OpenImage(Filename.c_str(), corona::PF_R8G8B8A8);
	if (img != 0)
	{
		glGenTextures(1, &GLName);
		glBindTexture(GL_TEXTURE_2D, GLName);

		glTexImage2D(GL_TEXTURE_2D, 0, 4, img->getWidth(), img->getHeight(), 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, img->getPixels());
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		delete img;
		Valid = true;
	}
}
I'm trying to load a 256x256 png file. I know it gets to the glTexImage2D without any problems. It all works just fine... it's just that the quad isn't textured. I am binding it before drawing the quad:
tex->Bind();
		glLoadIdentity();
		glTranslatef(0.0f, 0.0f, -5.0f);
		glBegin(GL_QUADS);
			glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); 
			glVertex3f(1.0f, -1.0f, 1.0f); glTexCoord2f(1.0f, 0.0f); 
			glVertex3f(1.0f, 1.0f, 1.0f); glTexCoord2f(1.0f, 1.0f); 
			glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f);
		glEnd();
Here's Bind():
void Texture2D::Bind()
{
	if (Valid)
		glBindTexture(GL_TEXTURE_2D, GLName);
}
Yes, debugging it shows that GLName = 1, so I know it has the right one. It's just that the quad isn't textured when it should be. I really have no idea what's wrong - I think it's my glTexImage2D call, but that looks fine to me...?

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!