Archived

This topic is now archived and is closed to further replies.

glPrint Function

This topic is 5441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
}
// ---------------------------------------------------------

  

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
quote:
Original post by Dave Hunt
Try replacing "if (fmt = NULL)" with "if (fmt == NULL)".



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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Arrays are actually just a pointer to an address in memory, in fact, have you ever noticed the glxxv functions? Their arguments say that they accept a pointer, and to use them you pass an array. What you are actually doing is passing a pointer to the array''s starting address.

The moral is that pointers and arrays are more closely related than you think , and that pointers are your friend .

Share this post


Link to post
Share on other sites
Pointers seem dangerous to use and are quite confusing to me. Though it seems they are also quite useful, and if I could just understand them well enough then I could actually use them too. (I just know that after running this and getting the thing saying it can''t read 0x0000000 or whatever than aim started acting funny giving me the same type of error, and then I had to re-install aim..)

Share this post


Link to post
Share on other sites