Jump to content
  • Advertisement
Sign in to follow this  
Kanzure

OpenGL A weird bug in my OpenGL engine..

This topic is 5095 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 crossposted. My game is script based, and I have the scripts load up the right images for each in-game object. When the images are loaded, the textures are generated and `bound` to "image->texture" (an unsigned int). I have 3 images loaded. When I run my game, I see 2 quads, both the proper size, except only one is displaying a texture. The other is white. I have it set up so that when I press 'space' the one with the texture changes to another quad size and texture. It changes to a white quad (proper size). The quad with the proper texture is only proper because it's the last texture loaded. It's the last one being sent to OpenGL. Edit: That sounds confusing. In other words, I have a quad that is white and doesn't have the right texture, even though another texture works. The only texture that does work is the last one loaded. With the bug in mind, here's my code. CImage::setImage() is called during "init", and then draw() is called in the main game loop.
void CImage::setImage(std::string filename2) {
	this->image = load(filename2.c_str());
	this->filename = filename2;
	needsToBeBound = 1;
	my_texture = -1;
glEnable(GL_TEXTURE_2D);
		glGenTextures(1, &my_texture);
		if(this->my_texture > 0) {
		} else {
			printf("Error.");
// gee, I need something more creative here. heh'
		}
	//	std::cout << "Texture ID: " << my_texture << std::endl;
		unsigned char *Data = (unsigned char *) (image->pixels);
		unsigned char temp;
		for (int i=0;   i  < (image->w*image->h)*3;   i=i+3) {
			temp = Data;
			Data = Data[i+2];
			Data[i+2] = temp;
		}

		unsigned char *Data2 = (unsigned char *)malloc((image->w*image->h)*4);
		int p = 0;
		for(int i = 0; i < (image->w*image->h)*4; i=i+4) {
			Data2 = Data

; Data2[i+1] = Data[p+1]; Data2[i+2] = Data[p+2]; if((Data

== 0) && (Data[p+1] == 0) && (Data[p+2] == 0)) { Data2[i+3] = 0; } else { Data2[i+3] = 255; } p = p + 3; } glBindTexture(GL_TEXTURE_2D,my_texture); glTexImage2D(GL_TEXTURE_2D,0,4,image->w,image->h,0,GL_RGBA,GL_UNSIGNED_BYTE,Data2); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glBindTexture(GL_TEXTURE_2D,my_texture); needsToBeBound = 0; free(Data2); } void CImage::draw() { glBindTexture(GL_TEXTURE_2D,my_texture); // when I comment out the above, everything is the LAST loaded texture..uhh..but if I // keep it in, some textures are white. WHY?! Am I doing something wrong when // loading that overwrites the last loaded texture?? glBegin(GL_QUADS); glTexCoord2f(0.0f,-1.0f);glVertex3i(x,y, y); glTexCoord2f(1.0f,-1.0f);glVertex3i(image->w+x,y, y); glTexCoord2f(1.0f,0.0f);glVertex3i(image->w+x,image->h+y, y); glTexCoord2f(0.0f,0.0f);glVertex3i(x,image->h+y, y); glEnd(); }

Any ideas why my last texture being loaded is 'overwriting'(?) the others? Is that even what it's doing?

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!