Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Posts
    3

    C++ OpenGL Text Drawing Problem

    Hi, I've browsed the forums for help and found many people struggling with this VTM. However I have not managed to find a solution to my particular problem so any help is appreciated.

    Firstly, if I use a 32 bpp version of the font.tga file, it does not seem to read in correctly, and I end up with an image looking like attachment1.jpg. If however I change the bpp to 24, I then end up with a scene looking like attachment2.jpg.

    As you can see, I have changed the clear color in attachment2.jpg to determine if geometry was still drawing, and it is. Therefore it seems to be a lighting problem. The two bits of code that I guess the problem lies within are posted below.

    Thankyou in advance for any help.

    Code:
    GLvoid drawScene(GLvoid)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	//Perspective pass
    	establishProjectionMatrix(windowWidth, windowHeight);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    	glDisable(GL_BLEND);
    	glEnable(GL_LIGHTING);
    	
    	glTranslatef(0,0,-80.0f);
    	glRotatef(cubeRotateX, 1, 0, 0);
    	glRotatef(cubeRotateY, 0, 1, 0);
    	
    	//Update lights
    	for(int i = 0; i < (int)Light::lights.size(); i++)
    	{
    		double randomNumber = (double)SDL_GetTicks() + seed[i];
    		float x = (float) sin(randomNumber / 1600.0f) * (float) cos(randomNumber / 1200.0f) * 30.0f; 
    		float y = (float) sin(randomNumber / 900.0f) * (float) cos(randomNumber / 1400.0f) * 30.0f;
    
    		Light::lights[i]->setPosition(x, 30.0f, y);
    		Light::lights[i]->updateLight();
    	}
    
    	drawGrid();
    
    	//Orho pass
    	glColor3f(1.0f, 1.0f, 1.0f);
    	glDisable(GL_LIGHTING);
    	setOrtho(windowWidth, windowHeight);
    	displayFPS();
    	glFlush();
    	
    	SDL_GL_SwapBuffers();
    }
    Code:
    GLvoid GLEngine::drawText(GLint x, GLint y, const char *in_text, ...)
    {
    	char text[256];
    
    	va_list	ap;
    	va_start(ap, in_text);
    	vsprintf(text, in_text, ap);
    	va_end(ap);
    
    	glEnable(GL_TEXTURE_2D);
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    
    	glBindTexture(GL_TEXTURE_2D, fontTexture->texID);
    
    	glMatrixMode(GL_MODELVIEW);
    	glPushMatrix();
    	glLoadIdentity();
    
    	glTranslated(x, y, 0);
    	glListBase(fontBase - 32);
    	glCallLists(strlen(text), GL_BYTE, text);
    
    	glMatrixMode(GL_MODELVIEW);
    	glPopMatrix();
    }
    Attached Images Attached Images

  2. #2
    Join Date
    Jun 2007
    Posts
    3
    Nevermind, problem solved.

    For the record, it was the call to glEnable(GL_TEXTURE_2D); within the drawText function that was causing this. To fix it, I placed a glDisable(GL_TEXTURE_2D); at the end of this function and now it seems to render correctly.

Tags for this Thread

Posting Permissions

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