Visual C++ 2010 Express... how do I draw a line?

Hi everyone.

I would like to start experimenting with OpenGL in a MS-Windows environment, so I’ve installed Microsoft Visual C++ 2010 Express. C++ is the language I am most familiar with.

But how do I start from there on?

I would like to find a step-by-step guide to draw a line or a circle.

I’ve tried one or two tutorials with no luck whatsoever.

I’d appreciate it if someone could point me to the right direction.

Thanks :slight_smile:

tutoials, maybe ?!!Getting-started/Creating-a-window

basically you need 2 c++ libraries, one to create a window andd another to load all the opengl functions (pointers)
i recommend:

SDL2 would be another option for window creation: (a big library)

here another example:

I tried the first link but I cannot set it up. Generating with CMake produces errors (since i use Studio 2010 and the instructions are for 2012 I just picked the right choice for me in the configuration).

Why does it have to be so difficult?


I would like to help, but I have no knowledge of Visual Studio at all. Here are my ideas that are sadly very broad:

a) upgrade your visual studio
b) solve the CMake problems
c) use Linux (doesn’t make things easier, but I would be able to help)

To answer your question, why things have to be so complicated. The reason is simple, OpenGL is not an API that tries to optimize your productivity. It just opens a window to have a consistent API over several operating systems to enable you access to GPU computing for but not limited to the rasterization pipeline. It’s pretty bare bone, and want to stay that way. Vulkan even wants to be more bare bone. If you want a simpler life, take an existing engine they are not without reason so popular. If you want to really learn how things really work, use OpenGL or Vulkan, but don’t expect things to be easy.

are you able to make a simple “hello world” console application ??
–> new projct --> console application -> give it a name
–> add a new cpp file called “main.cpp”, just cout a “hello world”

#include <iostream>
int main()
std::cout << "hello world" << std::endl;
return 0;

until now, you dont need any external libraries

part 1: creating a window

to be able to create a window in which you can draw, you need GLFW
but if you do that:

#include <GLFW/glfw3.h>

you will get a compile error: “no such file found”
download + unzip glfw (32bit pre-compiled windows binaries)

in it, you will find a directory called “include”, in it, you will find a directory called “GLFW”
copy the include directory into your project, where your “main.cpp” is located
open the project’s properties --> add a new “include directory” --> add the copied folder path

now you should be able to compile:

#include <iostream>
#include <GLFW/glfw3.h>
int main()
std::cout << "hello world" << std::endl;
return 0;

to create a window, replace that code with this:

compilation will fail, because you are missing some .lib files
what you just downloaded --> in it, you will find a directory called “lib-vc2010”, in it you’ll find “glfw3.lib”
beside the “include” folder in your project directory, create another folder called “lib”, copy the glfw3.lib into it
open the project’s properties --> add a new “library directory” --> add the path to the lib folder
then go to the “linker” section, “input” --> “additional dependencies” --> add “glfw3.lib”

now you should be able to compile the example code to create a window
(if not, you should read something about “using c++ libs”, “compiling / linking”)

part 2: loading openGL functions

once you have downloaded glew windows 32 binaries …

… you will again find a “include” folder in it, copy the “GL” folder into your “include” folder where you already have “GLFW”
beside that, there is a “lib” folder, in it a “Release” folder, in it a “Win32” folder, in it a file called “glew32s.lib”
–> copy that file into your lib folder
–> go again into your project properties --> linker section --> input --> additional deps --> add “glew32s.lib”
–> in addition to that, add “OpenGL32.lib”

then in your example code, right BEFORE #include <GLFW/glfw3.h>, add:
#include <GL/glew.h>

now you can easily replace ANY code piece you find at
like that:

Thanks everybody :slight_smile:

John, a big thank you for your step by step instructions.

Using Microsoft Visual Studio 2012 I created a console application project, like you suggested. The template code was different there so I kept it and the simple “Hello World” program worked:

#include "stdafx.h"
#include <iostream>

int _tmain(int argc, _TCHAR* argv[])
std::cout << "hello world" << std::endl;
return 0;

I downloaded GLFW and copied the “include” directory in the dir where ConsoleApplication1.cpp is.

( …\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\include )

Then I let Visual Studio know about it:
Project > Properties > Configuration Properties > C/C++ > General > Additional Include Directories

And the word include in line: #include <GLFW/glfw3.h> stopped being red-underlined, showing that at least that part is ok.

But when I copied the suggested code, keeping the deviation int _tmain(int argc, _TCHAR* argv[]):

#include "stdafx.h"
#include <iostream>
#include <GLFW/glfw3.h>

int _tmain(int argc, _TCHAR* argv[])
   GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
        return -1;

    /* Make the window's context current */

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
        /* Render here */

        /* Swap front and back buffers */

        /* Poll for and process events */

    return 0;

and tried to build it I get errors. I don’t know how to post them here, though, as when I copy them and try to post I get this forum error: Post denied. New posts are limited by number of URLs it may contain and checked if it doesn’t contain forbidden words. And when I tried to upload a screenshot as attachment I only saw a possibility to upload something from another site. Or else I didn’t figure out the interface?

dont use “precompiled headders” or any other additional option BEFORE your create the project:

after you’ve clicked on “Console Application” in the create project menu:
–> uncheck “precompiled headders”
–> uncheck “security dev lifecycle checks”
–> check “empty project”

then you wont have any starting code etc

(i think i found what i did wrong)

Right click on “source files” and add your hello world file.

thanks paul, I saw it eventually :slight_smile:

Now, I follow john’s instructions:
I copied the include directory in the project directory where main.cpp is:

I included the iclude directory to the project (Properties > C/C++ > General > Additional Include Directories)

It seems to recognize the include, in the code (no red underline) but when I build and try to debug I get all these messages:

'ConsoleApplication2.exe' (Win32): Loaded 'G:\Users\user\Documents\Visual Studio 2012\Projects\ConsoleApplication2\Debug\ConsoleApplication2.exe'. Symbols loaded.
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64
tdll.dll'. Cannot find or open the PDB file.
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded.
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded.
The program '[5684] ConsoleApplication2.exe' has exited with code 0 (0x0).

and no run. Am I doing something wrong, again?

Follow the tutorial but use the latest versions of the libs.

I just tried googling “Visual C++ 2010 OpenGL Example” and got many hits.
The first one is a pretty good YouTube tutorial on how to set up an OpenGL project.

thanks paul. Btw I had walked through this one already, before I came here. IIRC in the end I got a blue screen that should make me very happy, but I just wanted to see how to draw something, anything, a line. Anyways, I applied the changes you indicated at and the warnings are gone. Thanks :slight_smile:

Carmine, I tried a couple but didn’t manage to draw a line and thus I came here. And still I don’t have a line. (Of course, I have a lag reacting to posts here).

In the meanwhile, the Visual Studio trial version is expired. What is there to do, except from buying it? Is there other free software that I could use?