Skip to main content
GameDev.net gamedev.net
🔒 Locked

Silly translation issues

Started by Analazon Feb 23, 2005 at 4:34 PM 1 replies 650+ views
Original Post
Analazon
Analazon
Been trying to build an OpenGL 2d engine for a few 2d projects that I've either always wanted to build, or would like to build and have gotten other people to do the hard work for (design doc, concept, etc... ;)). My problem lies in that I'm trying to make "UI Strings" that can contain text and images. I'm using a vector to store the structs which consist of either a string or a sprite, and an identifier to tell which type it is. According to MSDN, glCallLists() doesn't clear any state changes that it makes. This *seems* to be true, as when I put multiple pieces of text in it they display next to each other right. However, when I try to shove an image between them, it displays itself at the origin of the string. This is my UI string rendering function:

void cUIString::Draw()
{
	int i;
	GLenum Error;

	// preserve OGL state outside of here
	glPushMatrix();
	glPushAttrib(GL_LIST_BIT);

	
	// set up color (looks odd if called after position is set up)
	glColor3f(1.0f, 1.0f, 1.0f);

	// set up the position
	glLoadIdentity();
	glTranslatef(xPos, yPos, 0.0f);
	glRasterPos2f(0.0f, 0.0f);
	

	for(i = 0; i < MyData.size(); i++)
	{
		if(MyData.ElementType == UISTRING_TEXT)
		{			
			glListBase((unsigned int)MyFont->GetDispListName() - 32);
			glCallLists(strlen(MyData.Text), GL_UNSIGNED_BYTE, MyData.Text);
		}
		else
		{
			// funny translations
			glPushMatrix();
			glTranslatef(0.0f, -MyData.Sprite.GetYSize(), 0.0f);
			MyData.Sprite.Draw();
			glTranslatef(MyData.Sprite.GetXSize(), 0.0f, 0.0f);
			glPopMatrix();
		}
	}
	glPopAttrib();
	glPopMatrix();

	Error = glGetError();
	if(Error != GL_NO_ERROR)
	{
		MessageBox(NULL, "ERROR", "A GL Error has occured in cUIString::Draw", MB_OK);
		PostQuitMessage(0);
	}
	glLoadIdentity();
}
_______~Analazon
Kalidor
Kalidor
Could you post your code for creating the string display list and also your sprite's Draw() function?

It's probably because when you render your text it uses the raster position, which is updated as you draw your text, but when you render your sprite it uses the modelview matrix, which isn't updated. You would need to translate it to the correct spot in the string before rendering.

And also...
Quote:
glPushMatrix();
glTranslatef(0.0f, -MyData.Sprite.GetYSize(), 0.0f);
MyData.Sprite.Draw();
glTranslatef(MyData.Sprite.GetXSize(), 0.0f, 0.0f);
glPopMatrix();

That second glTranslatef() call won't do anything because you're popping the matrix right after it. I'm not sure what you're trying to do with that, but just thought I'd let you know.
Analazon
Analazon
Fixed it all. You were quite right. However, I couldn't give up last night and ended up fixing it the "hard" way. And yeah, that second translatef was in the wrong place. That's what I get for coding when I should be sleeping.
_______~Analazon

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.