Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: getting textures to work

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Pennsylvannia
    Posts
    103

    getting textures to work

    I'm trying out glfont, a tool which renders characters in openGL by mapping character textures onto gl quads. I haven't learned about textures yet, so I'm just following the example code as closely as possible. Code is on the faq page here: http://students.cs.byu.edu/~bfish/glfontfaq.php

    The problem I'm having is I'm getting solid strips instead of text. This problem is mentioned in the faq, and it claims you need to enable texture mapping and alpha blending, with:

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    and lastly to try playing around with glScale. I did all three, and I'm still getting solid strips.

    Here's the whole program:
    Code :
    #include "stdafx.h"
    #include "glfont.h"
    #include <glut.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
     
    GLFONT arial_r_12; // global font object
     
    void init(void)
    {
      glClearColor (0.0, 0.0, 0.0, 1.0);
     
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
     
     
     
    void display(void)
    {
        glClear (GL_COLOR_BUFFER_BIT);
     
        glFontBegin(&amp;arial_r_12);
            glTranslatef(30, 30, 0);
    	glScalef(8.0,8.0,0.0);
            glFontTextOut("HELLO WORLD!!!", 5, 5, 0);
        glFontEnd();
     
        glutSwapBuffers();
    }
     
    void reshape (int w, int h)
    {
       glViewport (0, 0, (GLsizei) w, (GLsizei) h);
       glMatrixMode (GL_PROJECTION);
       glLoadIdentity ();
       glOrtho(0, 640, 0, 480, -1, 1);
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
    }
     
     
     
    int _tmain(int argc, char** argv)
    {
     
       if (!glFontCreate(&amp;arial_r_12, "C:\\Program Files\\glFont\\Arial_r_20.glf", 0))
       {
    	   return 0;
       }
     
       glutInit(&amp;argc, argv);
       glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
       glutInitWindowSize (640, 480);
       glutInitWindowPosition (100, 100);
       glutCreateWindow (argv[0]);
       init ();
       glutDisplayFunc(display);
       glutReshapeFunc(reshape);
       glutMainLoop();
     
       glFontDestroy(&amp;arial_r_12);
     
       return 0;
    }
    Striving for proficiency...

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2006
    Location
    South Tyrol
    Posts
    20

    Re: getting textures to work

    I'm not familiar with glfont, but I think the problem is that you're calling glFontCreate before an OpenGL context was created.
    Try moving the call to glFontCreate after your OpenGL initialization, i.e. after the call to glutCreateWindow.

    Hope that helps!

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Pennsylvannia
    Posts
    103

    Re: getting textures to work

    AH! That was it. Thank you so much, tomtrenki!
    Striving for proficiency...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •