Jump to content
  • Advertisement
Sign in to follow this  

glCopyTexImage2D returning 180 turned textures?

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

Im using C++, SDL, OpenGl to code a 2d Game. I started writing a little PreRendering function to make my rendering more efficient (im having 16*200 stripes in 256*256 textures which are static and therefor some of them could rendered once to a 256*256 so i would have much less blits) and after reading the nehe tutorial about it I used glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,256,256,256,0); to copy the rendered stuff into a new texture. Problem is only that when I blit it again (with the same texture coordinates like all textures) I get the image 180° degrees turned. Maybe its that my normal textures are turned (they're loaded from SDL_Surfaces)? Also does someone know why GL_RGB works but when I use 3 as Argument (like in my normal texture loading function) I get a white texture?

Share this post

Link to post
Share on other sites
Some picture editing programs store bmp and/or tga's upside down...

(To be more precise: they store them alright but do not specify the direction in the header)

This might affect what you're seeing...


Share this post

Link to post
Share on other sites
So is there a possibilty to change the coords?

Yes. Can I convince you to post some source code and maybe some pictures?
Is that changing the texture matrix?

Yes, sort of. Changing the texture matrix will result in altered texture coordinates being used for the rendered scene. However these coordinates will not be static, a texture matrix transform will be applied per-render to achieve these results.

Share this post

Link to post
Share on other sites
I just noticed that it isnt 180° turned but vertically fliped ;)

So heres my normal texture generating code

bool bige_loadtexture (unsigned int width, char* filename, char* maskname, bige_texture &texture, unsigned int part, bool mask, bool RectangleMask)
SDL_Surface *temp, *temptext;
SDL_Rect src,dst;
int power=1;
if (temp = SDL_LoadBMP(filename))

for (; !((power>=(signed int)width)&&(power>=temp->h)); power=power*2)
texture.height = temp->h; // for my sprite class
texture.width = width; // ||
texture.size=power; // ||

src.x=width*part; //for cutting the right parts from the bitmap

//the intresting part:

temptext = SDL_CreateRGBSurface(SDL_SWSURFACE, power, power, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
SDL_FillRect(temptext, 0, SDL_MapRGB(temptext->format, 0, 0, 0));
SDL_BlitSurface(temp, &src, temptext, 0);
glGenTextures(1, &texture.img);
glBindTexture(GL_TEXTURE_2D, texture.img);
glTexImage2D(GL_TEXTURE_2D, 0, 3, power, power, 0, GL_RGBA, GL_UNSIGNED_BYTE, temptext->pixels);
// The same thing follows for mask

And here is the code that turns the Buffer into a texture:

PreRenders.push_back(Copy); // a vector that stores the pre renderd textures

PreRenders[PreRenders.size()-1].width //for the sprite class
= PreRenders[PreRenders.size()-1].size
= PreRenders[PreRenders.size()-1].height
= 256;

glGenTextures(1, &PreRenders[PreRenders.size()-1].img);
glBindTexture(GL_TEXTURE_2D, PreRenders[PreRenders.size()-1].img);


this is a part of my blitting function:


glVertex3f(x+texture.size*zoom, y,depth);
glVertex3f(x+texture.size, y+texture.size*zoom, depth);
glTexCoord2f(0, 1);
glVertex3f(x,y+texture.size*zoom, depth);


And heres an image of my problem:
above theres the normal game with NOT prerenderd background.
below its overlayed by the first prerendered texture (its blending because i havent yet written the code for the mask in the prerendering function)


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!