Advertisement

glPrint Function

Started by January 19, 2003 07:57 AM
10 comments, last by Sky 22 years, 1 month ago
I did the bitmap font tutorial thing, but when I compile and run i get a error message that says the memory at 0x000000 cannot be read... I think I need to make ap equal to something, but I''m not sure what... I used some message box things to find out exactly where the error occurs in my code...
  
// --------------------------------------Causes Error

GLvoid glPrint(const char *fmt,...) {
  char text[256]; // holds the string

  va_list ap; // pointer to list of arguements                        


  if (fmt = NULL) 
    return;
  
// between here...

  va_start(ap, fmt);
    vsprintf(text, fmt, ap);
  va_end(ap); 
// and here, is where the error occurs.


  glPushAttrib(GL_LIST_BIT);
  glListBase(base - 32);
   
  glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);
  glPopAttrib();
}
// ---------------------------------------------------------


// Draw Scene and Text -------------------------------------

int DrawGLScene(GLvoid) {   //Drawing Stuff

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear Screen adn Depth Buffer

  glLoadIdentity(); // Reset Modelview Matrix

  glTranslatef(0.0f,0.0f,-1.0f);

  glColor3f(1.0f*float(cos(cnt1)),1.0f*float(sin(cnt2)),1.0f-0.5f*float(cos(cnt1+cnt2)));
  glRasterPos2f(-0.45f+0.05f*float(cos(cnt1)), 0.35f*float(sin(cnt2)));

  glPrint("Sky''s Box made with NeHe - %7.2f", cnt1);
  cnt1+=0.051f;
  cnt2+=0.005f;
  return TRUE;
}
// ---------------------------------------------------------

  
i have found that this works better, though it will not work like before


    glPrint(char text[60]){   glPushAttrib(GL_LIST_BIT);  glListBase(base - 32);  glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);  glPopAttrib();}  



[edited by - lc_overlord on January 19, 2003 9:40:02 AM]
Advertisement
That works, but now I don''t think I can have variables printed.
Nonono I think it can''t be there...
1. Do you pass a NULL to the function?
2. Where EXACTLY the error occurs?
2 lc_overlord:
Change it to:
glPrint(char *text)
that should work better
PM Times change... Excuse my poor english!
it might have nothign to do with the print function...
I think too... it doesn''t make any sence...
PM Times change... Excuse my poor english!
Advertisement
Try replacing "if (fmt = NULL)" with "if (fmt == NULL)".
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);

that''s where it gave me the error ^
quote:
Original post by Dave Hunt
Try replacing "if (fmt = NULL)" with "if (fmt == NULL)".



that would probably work... I''ll try it later.


quote:
Original post by PM
lc_overlord:
Change it to:
glPrint(char *text)
that should work better


Perhaps but serioulsly,
1. i hate pointers.
2. it''s not like im going to need to print 5000 chars in one line, it just doesn''t fit.

This topic is closed to new replies.

Advertisement