Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Skybox or Text

  1. #1
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Skybox or Text

    I have this little problem i can't show both skybox and text at the same time - if i comment glPrint skybox works but then i don't see the text and vice versa
    Code :
    void DrawGLScene()
    {
    	double deltat;
    	deltat=GetTime();
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	DrawSkybox(0.0f,0.0f,0.0f);
    	CalculateNewPos((float)deltat);
    	glRotatef(my_position.rot_x,1.0f,0.0f,0.0f);
    	glRotatef(my_position.rot_y,0.0f,1.0f,0.0f);
    	glTranslatef(-my_position.x,-my_position.x,-my_position.x);
    	DrawSkybox(0.0f,0.0f,0.0f);								//problem here ?					
    	glPushMatrix();
    			glTranslatef(EARTH->x,EARTH->y,EARTH->z);
    			ShowObject(EARTH->model);
    	glPopMatrix();
    	glPushMatrix();
    		glDisable(GL_CULL_FACE);
            glTranslatef(0.0f,0.0f,5.0f);
            glBegin(GL_TRIANGLES);
    		glVertex3f(-2.0f,-2.0f,0.0f);
    		glVertex3f(2.0f,-2.0f,0.0f);
    		glVertex3f(0.0f,2.0f,0.0f);
    		glEnd();
    		glEnable(GL_CULL_FACE);
    	glPopMatrix();
    	glPushMatrix();
    		glMatrixMode(GL_PROJECTION);
    		glPushMatrix();
    		glLoadIdentity();
    		glOrtho(-1.0f,1.0f,-1.0,1.0f,-1.0f,1.0f);
    		glMatrixMode(GL_MODELVIEW);
    		glLoadIdentity();
    		glColor3f(1.0f,1.0f,1.0f);
    		glTranslatef(-0.9f,0.9f,0.0f);
    		glScalef(0.05f,0.05f,0.5f);
    		glPrint(10.0f,50.0f,0.0f,"x");      //problem here?
    		glMatrixMode(GL_PROJECTION);
    		glPopMatrix();
    		glMatrixMode(GL_MODELVIEW);
    	glPopMatrix();
    }
     
    void DrawSkybox(float x,float y,float z)
    {
    	glEnable(GL_TEXTURE_2D);
    	glDisable(GL_DEPTH_TEST);									//disables depth test
    	glDepthMask(0);												//so skybox will never cover any geometry
    	glBindTexture(GL_TEXTURE_2D,skybox_texture_id);
    	glBegin(GL_QUADS);
    	glColor3f(0.25f,0.59f,0.78f);
    	glTexCoord2f(0.0f,1.0f);									// front face
    	glVertex3f(-300.0f+x,-300.0f+y,-300.0f+z);
    	glTexCoord2f(1.0f,1.0f);
    	glVertex3f(300.0f+x,-300.0f+y,-300.0f+z);
    	glTexCoord2f(1.0f,0.0f);
    	glVertex3f(300.0f+x,300.0f+y,-300.0f+z);
    	glTexCoord2f(0.0f,0.0f);
    	glVertex3f(-300.0f+x,300.0f+y,-300.0f+z);
    	glTexCoord2f(0.0f,1.0f);									// left face
    	glVertex3f(-300.0f+x,-300.0f+y,300.0f+z);
    	glTexCoord2f(1.0f,1.0f);
    	glVertex3f(-300.0f+x,-300.0f+y,-300.0f+z);
    	glTexCoord2f(1.0f,0.0f);
    	glVertex3f(-300.0f+x,300.0f+y,-300.0f+z);
    	glTexCoord2f(0.0f,0.0f);
    	glVertex3f(-300.0f+x,300.0f+y,300.0f+z);
    	glTexCoord2f(0.0f,1.0f);									// right face
    	glVertex3f(300.0f+x,-300.0f+y,-300.0f+z);
    	glTexCoord2f(1.0f,1.0f);
    	glVertex3f(300.0f+x,-300.0f+y,300.0f+z);
    	glTexCoord2f(1.0f,0.0f);
    	glVertex3f(300.0f+x,300.0f+y,300.0f+z);
    	glTexCoord2f(0.0f,0.0f);
    	glVertex3f(300.0f+x,300.0f+y,-300.0f+z);
    	glTexCoord2f(0.0f,1.0f);									// back face
    	glVertex3f(300.0f+x,-300.0f+y,300.0f+z);
    	glTexCoord2f(1.0f,1.0f);
    	glVertex3f(-300.0f+x,-300.0f+y,300.0f+z);
    	glTexCoord2f(1.0f,0.0f);
    	glVertex3f(-300.0f+x,300.0f+y,300.0f+z);
    	glTexCoord2f(0.0f,0.0f);
    	glVertex3f(300.0f+x,300.0f+y,300.0f+z); 
    	glTexCoord2f(0.0f,1.0f);									// upper face
    	glVertex3f(-300.0f+x,300.0f+y,-300.0f+z);
    	glTexCoord2f(1.0f,1.0f);
    	glVertex3f(300.0f+x,300.0f+y,-300.0f+z);
    	glTexCoord2f(1.0f,0.0f);
    	glVertex3f(300.0f+x,300.0f+y,300.0f+z);
    	glTexCoord2f(0.0f,0.0f);
    	glVertex3f(-300.0f+x,300.0f+y,300.0f+z);
    	glTexCoord2f(0.0f,1.0f);									// lower face
    	glVertex3f(-300.0f+x,-300.0f+y,300.0f+z);
    	glTexCoord2f(1.0f,1.0f);
    	glVertex3f(300.0f+x,-300.0f+y,300.0f+z);
    	glTexCoord2f(1.0f,0.0f);
    	glVertex3f(300.0f+x,-300.0f+y,-300.0f+z);
    	glTexCoord2f(0.0f,0.0f);
    	glVertex3f(-300.0f+x,-300.0f+y,-300.0f+z);
    	glEnd();
    	glDepthMask(1);
    	glEnable(GL_DEPTH_TEST);
    	glDisable(GL_TEXTURE_2D);
     
    }
    and glPrint func taken from NeHe

    Code :
    void glPrint(double xrot,double yrot,double zrot,const char *fmt, ...)
    {
    	float length=0;									// Used To Find The Length Of The Text
    	char text[256];									// Holds Our String
    	va_list ap;										// Pointer To List Of Arguments
    	if (fmt == NULL)								// If There's No Text
    		return;										// Do Nothing
    	va_start(ap, fmt);								// Parses The String For Variables
    		vsprintf(text, fmt, ap);					// And Converts Symbols To Actual Numbers
    	va_end(ap);										// Results Are Stored In Text
    	for (unsigned int i=0;i<(strlen(text));i++)		// Loop To Find Text Length
    	{
    		length+=gmf[text[i]].gmfCellIncX;			// Increase Length By Each Characters Width
    	}
    	glRotated(xrot,1,0,0);							// Rotate Text
    	glRotated(yrot,0,1,0);
    	glRotated(zrot,0,0,1);
    	glTranslatef(-length/2,0.0f,0.0f);				// Center Our Text On The Screen
    	glPushAttrib(GL_LIST_BIT);						// Pushes The Display List Bits
    	glListBase(base);								// Sets The Base Character to 0
    	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);// Draws The Display List Text
    	glPopAttrib();									// Pops The Display List Bits
    }

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: Skybox or Text

    Incidentally, you draw the skybox twice, the first when identity is on the modelview is almost certainly wrong, you'd at LEAST want the rotation.

    Draw it once, probably before you load the view translate on the modelview after the rotate, but since it has a translate build into the rendering you could use that and leave the draw call after all the view xform is applied.

    Onto your question:

    w.r.t. the font disappearing, I suspect the problem is the depth test being enabled on the way out of the skydome, it may not be enabled exiting your other draw code, it's impossible to tell.

  3. #3
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Re: Skybox or Text

    The first one is removed(i tried something before and forgot to remove it)

    for the text - depth buffer is enabled all the time(except for skybox) and every other object is shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •