Thread: OpenGL bitmap fonts (NeHe lesson 13) and textures

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    29

    OpenGL bitmap fonts (NeHe lesson 13) and textures

    I am learning opengl from NeHe tutorials and I am currently on bitmap fonts: lesson 13; for learning purposes I wanted to add a shape with a texture for refreshing my memory and I have found a bug.

    When ever I load a texture the text that prints turns a very dark color. I have found to stop this from happening I use glDisable(GL_TEXTURE_2D); and then enable it to draw the texture.

    Code:
            glDisable(GL_TEXTURE_2D);
                Courier.printf("I AM A BANANA");
            glEnable(GL_TEXTURE_2D);
    I am still getting a bug. The first charactor that prints out is still that dark color I mentioned earlier; the rest of the text is fine though. The printf function looks like this:

    Code:
    void Text::printf(const char *fmt, ...)
    {
        char text[256];
        va_list ap;
    
        if (fmt == NULL)
            return;
    
    
        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();
    }
    What do I need to do to fix it. Thanks for any help.
    Last edited by rainmanddw; 11-12-2006 at 02:49 AM.

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    29
    ok instead of enableing and disabling textures i found this makes it white

    Code:
            glBindTexture(GL_TEXTURE_2D, 0);
            //glDisable(GL_TEXTURE_2D);
            Courier.printf("I AM A BANANA");
            //glEnable(GL_TEXTURE_2D);


    But I can't make it any other color besides white.


    Also here is how I load the font and text:

    Code:
    Text::Text(std::string name, int size, bool bold, bool underline,  bool italic)
    {
        int weight;
    
        if (bold)
            weight = FW_BOLD;
        else
            weight = FW_NORMAL;
    
        HFONT font;
    	HFONT oldfont;
    
    	base = glGenLists(96);
    
    	font = CreateFont(  -size,
                            0, 0, 0,
                            weight,
                            italic,
                            underline,
                            false,
                            ANSI_CHARSET,
                            OUT_TT_PRECIS,
                            CLIP_DEFAULT_PRECIS,
                            ANTIALIASED_QUALITY,
                            FF_DONTCARE|DEFAULT_PITCH,
                            name.c_str()
                          );
    
        oldfont = (HFONT)SelectObject(hDC, font);
    	wglUseFontBitmaps(hDC, 32, 96, base);
    	SelectObject(hDC, oldfont);
    	DeleteObject(font);
    
    }
    Last edited by rainmanddw; 11-12-2006 at 03:56 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL - look trough surface -nehe lesson
    By GanglyLamb in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 11:06 PM