Sign in to follow this  

what the?!

This topic is 4832 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

hello, i just worked out a wierd bug in my program that i cannot figure out why it did what it did. i have a GLuint which i store my font list, i declare it withen a class. then withen my buildFont function (which is in the same class) i had this typo ... GLuint fontBase = glGenLists (96); as you can see i put the type name infront of fontBase, even though i already declare it ... so when i printed say the text "bcd" it would come out "abc" ... whatever i typed in was an offset off ... and i first fixed the problem my chagning the starting point in my list from 32 to 31 ... but later found the typo ... so leaving the typename on when assigning the variable some how shifted where each byte is stored? how come this isnt an error?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Probably you defined a new local variable with the same name as the old one. This is perfectly legal; basically, the old variable disappears until the new one goes out of scope.

The first time you call glGenLists() it will probably give you a value of 1, so if the old variable was 0, that would account for the shift.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster who was really uavfun
Probably you defined a new local variable with the same name as the old one. This is perfectly legal; basically, the old variable disappears until the new one goes out of scope.


Not quite. If you have:

#include <iostream>

int i;

void function( void )
{
int i;
std::cout << i << std::endl; //<-- this is the local var
//... you can do this:
std::cout << ::i << std::endl; //<-- this is the global var
}

Share this post


Link to post
Share on other sites
Quote:
Original post by MaulingMonkey
//... you can do this:
std::cout << ::i << std::endl; //<-- this is the global var

Granted, but the local variable would be initialised to 1 (the first value returned from glGenLists()), and the global would still be uninitialised (and, depending on your system, this would be 0), so call glCallLists() with the global as your list base, you are actually starting from one list before the beginning of the allocated display lists.

[edit]Having looked again at your example, it seems that your offset is in the other direction, possibly glGenLists() returns 0, and your global was initialised to 1?[/edit]

SwiftCoder

Share this post


Link to post
Share on other sites

This topic is 4832 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this