My text doesn't display

This is a discussion on My text doesn't display within the Game Programming forums, part of the General Programming Boards category; I'm trying to display text on the screen, but my worst nightmare happens: the program compiles, no errors, but nothing ...

  1. #1
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498

    Question My text doesn't display

    I'm trying to display text on the screen, but my worst nightmare happens: the program compiles, no errors, but nothing happens when I run the program. All I get is a black screen.
    I wrote the code so that I code write text onto the screen by simply doing
    Code:
    glPrint("Hello World %2.2f", float_var);
    It's supposed to parse strings just like a real printf() would do.
    This is the code I'm using:

    Code:
    // this selects the current font to be used in drawing
    void buildfont() {
    	base = glGenLists(96);	// storage for 96 charecters
    	
    	aglUseFont(aglGetCurrentContext(),
    				kFontIDMonaco,		// Choose your font. These are listed in Fonts.h, 
    									// or use GetFNum() toolbox function.
    				bold,				// Style, Also in Fonts.h
    				24,					// 12 point			
    				32,					// start at 32 ...
    				96,					// go for 96 characters ...
    				base);
    }
    
    // supposed to look like an "official" opengl function :)
    void glPrint(const char *fmt, ...) {
    
    	char text[256];				// holds the string
    	va_list ap;					// pointer to list of arguments
    	
    	if (fmt == NULL)			// make sure there is text here
    		return;
    		
    	va_start(ap, fmt);			// parses the string for variables
    	vsprintf(text, fmt, ap);	// convert the symbols into actual numbers
    	va_end(ap);					// results are stored in text
    	
    	glPushAttrib(GL_LIST_BIT);	// pushes the display list bits
    	glListBase(base-32);		// sets the base charecter to 32
    	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// draws the display list text
    	glPopAttrib();				// pops the display list bits back to the way it was before
    }
    Does the problem lie within the Apple specific code, agl? Or am I doing something wrong with GLUT?

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Are you calling glRasterPos2(i/f) before trying to print? If not try that.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  3. #3
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    yes.

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    ty something like:
    Code:
    glPushMatrix();
    		glTranslatef(0,0,-8);
    		glColor3f(1.0f,0.0f,0.0f);
    		glRasterPos2f(-9.95f,6.5f);
    		glPrint("Hello World %2.2f", float_var);
    glPopMatrix();
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    Still doesn't work. It's got to be something with my text functions, because triangles and quads display fine.

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    I don't have time to sort through details, but here's my function for drawing the FPS to the screen.
    Code:
    void drawFPS() {
    
      static char fpsBuf[100] = {0};
    
      glDisable(GL_TEXTURE_2D);
      glDisable(GL_FOG);
      //glShadeModel(GL_FLAT);
    
      glMatrixMode(GL_PROJECTION);
      glPushMatrix();
      glLoadIdentity();
      glOrtho(-0.5, 639.5, -0.5, 479.5, -1.0, 1.0);
    
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
    
      static int frames = 0;
      static int t0 = 0;
      frames++;
      GLint t = glutGet(GLUT_ELAPSED_TIME);
      if (t - t0 >= 2000) {
        GLfloat seconds = (t - t0) / 1000.0;
        GLfloat fps = frames / seconds;
        sprintf(fpsBuf, "FPS: %f", fps);
        t0 = t;
        frames = 0;
      }
    
      glColor3f(1.0f, 1.0f, 1.0f);
      printString(GLUT_BITMAP_HELVETICA_18, fpsBuf);
    
      glMatrixMode(GL_PROJECTION);
      glPopMatrix();
      glMatrixMode(GL_MODELVIEW);
    
      glShadeModel(GL_SMOOTH);
    }

  7. #7
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Having slept on this, just a thought, did you try to disable/enable GL_TEXTURE_2D ?
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  8. #8
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    I don't have time to sort through details, but here's my function for drawing the FPS to the screen.
    But what does printString() do? (it's a user-supplied function, right?)

    Having slept on this, just a thought, did you try to disable/enable GL_TEXTURE_2D ?
    I hadn't enabled it. I tried enabling it. No change.

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >But what does printString() do? (it's a user-supplied function, right?)
    wups...

    Code:
    void printString(void* font, const char* str, int x = 10, int y = 10) {
    
      glRasterPos2i(x, y);
      int len = strlen(str);
      for (int i = 0; i < len; i++) {
        glutBitmapCharacter(font, str[i]);
      }
    }

  10. #10
    User
    Join Date
    Jan 2006
    Location
    Canada
    Posts
    498
    YES!! I finally got it to work! thankyou thankyou thankyou thankyou....

  11. #11
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    What finally got it working?
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  12. #12
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by xds4lx
    What finally got it working?
    my code

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 07:39 AM
  2. create a small screen with conio.c
    By Ucom-c++ in forum C Programming
    Replies: 15
    Last Post: 05-18-2007, 01:51 AM
  3. Deleting Text from a Text file
    By Daved in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2006, 09:47 PM
  4. Small HTML question
    By Thantos in forum Tech Board
    Replies: 4
    Last Post: 12-29-2003, 12:37 AM
  5. display problem after retrieving from text
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 01-29-2002, 06:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21