🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problem with lesson 13

Started by
0 comments, last by Caste 15 years, 9 months ago
Hello I haven't any bug but the text doesn't appear when running the programm. #include <SDL/SDL.h> #include <windows.h> // Header File For Windows #include <math.h> // Header File For Windows Math Library ( ADD ) #include <stdio.h> // Header File For Standard Input/Output ( ADD ) #include <stdarg.h> // Header File For Variable Argument Routines ( ADD ) #include <gl\gl.h> // Header File For The OpenGL32 Library #include <gl\glu.h> // Header File For The GLu32 Library //#include <gl\glaux.h> // Header File For The GLaux Library HDC hDC=NULL; // Private GDI Device Context HGLRC hRC=NULL; // Permanent Rendering Context HWND hWnd=NULL; // Holds Our Window Handle HINSTANCE hInstance; // Holds The Instance Of The Application GLuint base; // Base Display List For The Font Set GLfloat cnt1; // 1st Counter Used To Move Text & For Coloring GLfloat cnt2; // 2nd Counter Used To Move Text & For Coloring bool keys[256]; // Array Used For The Keyboard Routine bool active=TRUE; // Window Active Flag Set To TRUE By Default bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc GLvoid BuildFont(GLvoid) // Build Our Bitmap Font { HFONT font; // Windows Font ID HFONT oldfont; // Used For Good House Keeping base = glGenLists(96); // Storage For 96 Characters ( NEW ) font = CreateFont(-24, // Height Of Font ( NEW ) 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch "Courier New"); // Font Name oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32 SelectObject(hDC, oldfont); // Selects The Font We Want DeleteObject(font); // Delete The Font } GLvoid KillFont(GLvoid) // Delete The Font List { glDeleteLists(base, 96); // Delete All 96 Characters ( NEW ) } GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine { char text[256]; // Holds Our String va_list ap; // Pointer To List Of Arguments if (fmt == NULL) // If There's No Text return; // Do Nothing va_start(ap, fmt); // Parses The String For Variables vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers va_end(ap); // Results Are Stored In Text glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW ) glListBase(base - 32); // Sets The Base Character to 32 ( NEW ) glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text ( NEW ) glPopAttrib(); // Pops The Display List Bits ( NEW ) } int InitGL(GLvoid) // All Setup For OpenGL Goes Here { 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 BuildFont(); // Build The Font return TRUE; // Initialization Went OK } int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(0.0f,0.0f,-1.0f); // Move One Unit Into The Screen 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("Active OpenGL Text With NeHe"); // Print GL Text To The Screen cnt1+=0.051f; // Increase The First Counter cnt2+=0.005f; // Increase The Second Counter glFlush(); SDL_GL_SwapBuffers(); return TRUE; // Everything Went OK } int main(int argc, char *argv[]) { int width = 640; int height = 480; SDL_Init(SDL_INIT_VIDEO); SDL_Surface* ecran = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL); int continuer = 1; //initialisation /* glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective(70,(double)640/480,1,1000);*/ if (height==0) // Prevent A Divide By Zero By { height=1; // Making Height Equal One } glViewport(0,0,width,height); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glLoadIdentity(); // Reset The Projection Matrix // Calculate The Aspect Ratio Of The Window gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix glLoadIdentity(); SDL_Event event; InitGL(); while (continuer) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: continuer=0; break; case SDL_KEYUP: switch (event.key.keysym.sym) { case SDLK_ESCAPE: continuer=0; break; case SDLK_RETURN: break; default : break; } break; } } DrawGLScene(); } if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class { //MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION); hInstance=NULL; // Set hInstance To NULL } KillFont(); // Destroy The Font SDL_FreeSurface(ecran); SDL_Quit(); return 0; } I use SDL and Windows.
Advertisement
Have you tried positioning the text at (0,0)? Setting the color to just plain white? Because then the computation of color or position is the problem, but it might be everything here.
And please use the [ source lang = "cpp" ] [ / source ] tags for code segments!

This topic is closed to new replies.

Advertisement