Jump to content
  • Advertisement

C++ Text. Legacy OpenGL 1.5, FreeGLUT

8Observer8

1319 views

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



2 Comments


Recommended Comments

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.

Share this comment


Link to comment

@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."

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By babaliaris
      Hello!
      I'm trying to find a good math library to use in my game engine. Because I need good DLL support, and c++ has tired me with DLLs, I ended up choosing C. I found CGLM but maybe you know something better  Of course I won't create the entire engine in C, I will use a lot of c++ but the DLL (which will include the renderer and any GL calls) will be made purely in C.
      Thank you.
    • By Eternal Paladin
      Hello everybody,
      I'm a solo developer / writer /designer currently working on a story-based RPG set in the modern era. I'm at the concept stage of game and also just looking for anybody who would be interested in helping me out! Any and all aid will be greatly appreciated. 

      Please message me or add me on discord (Merlin#2647) if interested, thanks!
    • By congard
      Hello! There was a question about performance. I tried to combine (if possible) the shaders into one for rendering in one pass. For example, SSR and Bloom (search for bright areas), blur: DOF and Bloom. But now there is a need to put the output in textures of different sizes. This raises the question: if I split all the shaders (postprocessing) and render the image in several passes (for example, ssr → bloom → blur bloom → blur dof instead of screenspace (ssr and bloom) → blur (bloom and dof)), how much performance can suffer? And in general, merging shaders for rendering in one pass, good practice? I will be grateful for the answer
    • By tamlam
      Hello all,
      I am trying to do animation by rolling a cube (1x1x1) along x_Axis.  I just want to roll this cube 90 degrees along the edge (parallel with y_Axis) in three times, then stop. 
      Then rolling within 45 degrees. then stop.
      When I use OpenGL to do animation, it always rolls in cycle time. I do not know how to make the animation with different actions as I draw in the below image.
      Please give me advice or useful links to reference. Thanks a lot.
      rollingCUbe.bmp
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!