glCopyTexImage2D returning 180 turned textures?

Started by
10 comments, last by ........................................ 18 years, 5 months ago
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?
Advertisement
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...

Cheers
So to get right that i use the right texture coordinates and not have all my textures stored the wrong way around here are my coordinates:

0,0 top left
1,0 top right
1,1 lower right
0,1 lower left
Not quite. OpenGL stores texture texture coordinates so that (0.0, 0.0) is the lower left and (1.0, 1.0) is the upper right. See this tutorial. I hope that helps!
Or another solution is to modify texture matrix...
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
So is there a possibilty to change the coords?
Is that changing the texture matrix?

because then i would change the matrix of each loaded texture and use the right coords in my blitting function so that i can use the generated texture with the same function..
Quote:So is there a possibilty to change the coords?

Yes. Can I convince you to post some source code and maybe some pictures?
Quote: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.
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		src.y=0;		src.w=width;		src.h=temp->h;		dst=src;		dst.x=dst.y;				//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);		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);  	}// 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);glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,256,256,0);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);


this is a part of my blitting function:
glBegin(GL_QUADS);glTexCoord2f(0,0);					glVertex3f(x,y,depth);glTexCoord2f(1,0); 					glVertex3f(x+texture.size*zoom, y,depth);glTexCoord2f(1,1);glVertex3f(x+texture.size, y+texture.size*zoom, depth);glTexCoord2f(0,	1);glVertex3f(x,y+texture.size*zoom, depth);glEnd();


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)

http://photos1.blogger.com/blogger/3039/1190/1600/PreRenderProblem.jpg
so does someone know a way to load the SDL_Surface data vertically flipped?
Why don't You access internal data and flip it yourself ?
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]

This topic is closed to new replies.

Advertisement