Text. Legacy OpenGL 1.5, FreeGLUT

Published April 26, 2019
Advertisement

What if you need to draw text with simple graphics? For example, you have a task in your college to draw plots with some text using C++. You can still use deprecated/legacy OpenGL 1.1 and FreeGLUT.

This example shows how to draw a text using FreeGLUT and deprecated/legacy OpenGL 1.5. And this example shows how to set up FreeGLUT in Visual Studio 2015.

Text_FreeGlutOpenGL15Cpp.zip - Just download and run this solution in your version of Visual Studio.  But do not forget to set "Platform Toolset" to "Your Version Of VS" in the project settings. See screenshot:

Spoiler

PlatformToolset.png.018bde1d802005f5655212e332d57fcc.png

If you want to set up FreeGLUT from scratch then download the "Libs" folders and set settings by yourself:

Libs: Libs_FreeGlutOpenGL15.zip

Settings:

Spoiler

1.
Configuration: All Configurations
Platforms: All Platforms

C/C++ -> Genaral -> Additional Include Directories:
$(SolutionDir)Libs\freeglut-3.0.0-2\include

Linker -> Input -> Additional Dependencies
freeglut.lib

2.
Configuration: All Configurations
Platforms: Win32

Linker -> General -> Additional Library Directories:
$(SolutionDir)Libs\freeglut-3.0.0-2\lib\Win32

Build Events -> Post-Build Event
xcopy /y /d "$(SolutionDir)Libs\freeglut-3.0.0-2\lib\Win32\freeglut.dll" "$(OutDir)"

3.
Configuration: All Configurations
Platforms: x64

Linker -> General -> Additional Library Directories:
$(SolutionDir)Libs\freeglut-3.0.0-2\lib\Win64

Build Events -> Post-Build Event
xcopy /y /d "$(SolutionDir)Libs\freeglut-3.0.0-2\lib\Win64\freeglut.dll" "$(OutDir)"
 

main.cpp

Spoiler


#include <GL/freeglut.h>
#include <string>

void drawText(float x, float y, std::string text)
{
    glRasterPos2f(x, y);
    glutBitmapString(GLUT_BITMAP_8_BY_13, (const unsigned char*)text.c_str());
}

void draw()
{
    glClear(GL_COLOR_BUFFER_BIT);
    drawText(0, 0, "Hello, World!");
    glutSwapBuffers();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(256, 256);
    glutCreateWindow("Drawing Text");
    glutDisplayFunc(draw);
    glutMainLoop();
    return 0;
}

 

Text_FreeGlutOpenGL15Cpp.png.ce9c6d16db38e2d89a0aadbed600e087.png

0 likes 2 comments

Comments

8Observer8

I renamed a name of the blog entry:

  • from "Drawing a Text using FreeGLUT, OpenGL 1.5"
  • to "Text. Legacy OpenGL 1.5, FreeGLUT"

Because I need to add accent that it is legacy/deprecated OpenGL 1.1. I made this example to show the simplest way to draw a text using FreeGLUT and OpenGL 1.1.

April 26, 2019 08:01 AM
NubDevice

@8Observer8 When I see grandfather GLUT I cringe a little but FreeGLUT is still relevant especially for quick and dirty demos. Personally I stayed clear.  But being aware of your evaluation of GLFW also (which I liked), I see nothing wrong with this. (trying to make sense of your current activity). From what I've observed, you tend to want to target the technology that leans toward browser based or very low end/extremely easy entry. I can respect that, especially if the goal is to not exclude anyone. I think I may have wasted some years not sticking with a setup I liked and got a jump start on the meat and potatoes of what was being presented such as the sin wave in one of your other blog entries. A lot of amazing things bloom from the use of (trigonometry) sin. :) It's a lot of work to get openGL loaded up without utilities such as these. I'm excited to see what you do when you move to game play math concepts, spacial management, rendering or back end coolness... This is the second time I've looked at this and both times I thought, "yup that's a FreeGLUT crisp font."

April 27, 2019 07:32 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement