PDA

View Full Version : [Win32] 2D Text disappears at left



Dennis
09-29-2011, 10:50 AM
Hello everyone,

I want to create an OpenGL application which could show 2D text on the screen, which have to use a font.
I should like to do this without GLUT, and with pure OpenGL in Win32, so I have no glut function.

At the moment I use wglUseFontBitmaps method, and it displays the text fine and in the right font.

But when the beginning of the text becomes to much to the left (and only the beginning should disappear), the whole string disappears!

I don't know what kind of thing I could do now, I hope someone could help me with my problem.

Thanks in advance,

Dennis


Complete source (which has some unused functions because I use it as a default OpenGL start source) in attachments.

Also compiled version in attachments (so you could see the thing what's going wrong)

BionicBytes
09-30-2011, 08:42 AM
Could you not just post some of the relevant drawing code rather than expecting very busy people to trawl around your source looking for your problem.

Dennis
09-30-2011, 09:18 AM
Oh... yes of course, here it is:

draw:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
static float f = 0;
f-=.0005f; // maybe you have to change this speed, but I used this because my computer isn't very fast
glTranslatef(f,0.0f,-1.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glRasterPos2f(0, 0);

char* fmt = "Hello World, My name is Dennis";
char text[256];
va_list ap;
va_start(ap, fmt);
vsprintf(text, fmt, ap);
va_end(ap);

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

init (Initialize fonts):


HFONT font;
base = glGenLists(96);
font = CreateFont(-12,
0,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH,
LPCWSTR("Arial"));
HFONT oldfont = (HFONT)SelectObject(g.hdc, font);
wglUseFontBitmaps(g.hdc, 32, 96, base);
SelectObject(g.hdc, oldfont);
DeleteObject(font);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations