Game Development Community

GUI Texturing acts screwy

by Thor Zollinger · in Torque Game Engine · 01/28/2003 (7:18 am) · 4 replies

OK, I'm confused...

I'm creating a GUI control for a rotating scrolling map, but the texture coordinates are behaving oddly. The vertex's plot fine, but when I turn on the texturing and drag the control around on the screen in the GUI editor, the texture warps as if spherical environmental texturing is turned on.

It appears to be intentional, since the guibitmap control goes to a lot of trouble to calculate texture coordinates to correct for this. Tonight I'm going to try glDisable(GL_TEXURE_GEN_S) and for T and see if it turns it off.

Why would anyone turn on spherical environmental texture mapping on an ortho 2D control panel?
Is this a bug in the code?

Thor

#1
01/28/2003 (11:02 am)
Thor,

It might help to resolve your problem, particularly if it's obvious, if you posted a snippet of your rendering code.

- Melv.
#2
01/28/2003 (5:52 pm)
Hi Melv,
I'm modifying the guiRadarCtrl.cc by Matt Webster.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2270

Comment out this line in the original code so you don't get confused:
//dglDrawBitmapStretchSR(texture,dstRegion, srcRegion, false);

Then add in this section in as the next function block:
if (mTextureHandle) {
	        glTranslatef(center.x, center.y, 0);
		glDisable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		TextureObject* texture = (TextureObject *) mTextureHandle;
		//TextureObject* texture = (TextureObject *) mCompass; 
		glBindTexture(GL_TEXTURE_2D, texture->texGLName);

		//glDisable(GL_TEXTURE_GEN_S);  //  These didn't fix the problem.
		//glDisable(GL_TEXTURE_GEN_T);

		//glRotatef(30, 0, 0, 1);
		glColor4f(1.0, 1.0, 1.0, 0.7);  //  Compass Ring
		glBegin(GL_QUADS);
		    //  I had to use these texture coordinates to get the texture to match
			//  the width of the Quad center-screen rather than the standard 0 to 1.
			glTexCoord2f(-3, -3);  glVertex2f(-center.x, -center.y);
			glTexCoord2f(4, -3);  glVertex2f( center.x, -center.y);
			glTexCoord2f(4, 4);  glVertex2f( center.x,  center.y);
			glTexCoord2f(-3, 4);  glVertex2f(-center.x,  center.y);
		glEnd();

		glDisable(GL_TEXTURE_2D);
		glDisable(GL_BLEND);
	}

Compile, run the Example, install the radar control using the GUI editor, connect the bitmap up to fps/client/ui/radar_base.png, Apply it, then drag the control around the window.

The texture warps as if the surface it's on is a sphere. Move left and it warps into a thin vertical version of itself, move right and it expands out past the limits of the Quad. It does a similar trick top to bottom.

Any ideas on why?
#3
01/30/2003 (7:00 pm)
OK, Nobody seems to know, so I'll ask this a different way:

Why do you have to do all these calculations to get workable texture coordinates in guiBitmapCtrl.cc:

srcRegion.set(0,0,texture->bitmapWidth,texture->bitmapHeight);
  					dstRegion.set( ((texture->bitmapWidth*x)+offset.x)-xshift,
								      ((texture->bitmapHeight*y)+offset.y)-yshift,
								      texture->bitmapWidth,	
								      texture->bitmapHeight);
   				dglDrawBitmapStretchSR(texture,dstRegion, srcRegion, false);

I don't understand why the texturing isn't set up so you can do normal 0.0 to 1.0 texture coordinates like all other OpenGL commands.

Can anyone answer this?
How about you GarageGames guys?
I've tried everything I know to get past this already.
#4
01/30/2003 (10:32 pm)
Ah Hah!
I figured it out, and it's my fault. Sorry guys.
I used 'center' when I should have used 'mExtents'.
I've got it working now.