Question

I'm trying to learn OpenGL. I'm using the SFML window module for the context and gl3w as my loading library. I use SFML pretty often so it wasnt a problem to set it up for OpenGL following this tutorial:http://www.sfml-dev.org/tutorials/2.0/window-opengl.php

I could run the example code without any problems. I linked everything that I need for OpenGL (opengl32.lib and glu32.lib + sfml*.lib).

Then I followed this answer to get gl3w :How to set up gl3w on Windows?.

But now if I try to run this code which is mostly the example code from SFML

#include <SFML/gl3w.h>
#include <SFML/Window.hpp>

static const GLfloat red[] = { 1.0f, 0.f, 0.f, 1.f };

int main()
{
    // create the window
    sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);
    gl3wInit(); //ignore return value for now

    // load resources, initialize the OpenGL states, ...
    // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                //adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
            }
        }

        glClearBufferfv(GL_COLOR, 0, red);

        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

    // release resources...

    return 0;
}

I get following Linker errors.

1>OpenGL.obj : error LNK2019: unresolved external symbol _gl3wInit referenced in function _main
1>OpenGL.obj : error LNK2001: unresolved external symbol _gl3wViewport
1>OpenGL.obj : error LNK2001: unresolved external symbol _gl3wClearBufferfv

I double checked if I linked the libs correctly.

Im working on Windows 7 with Visual Studio 2013.

Anyone knows what I do wrong?

Was it helpful?

Solution

You forgot to compile gl3w.

Assuming that you already:

  • grabbed python script
  • ran it: python gl3w_gen.py
  • found gl3w.h glcorearb.h and gl3w.c files generated

There are two ways:

First way. Just include those files in your project, so it will be compiled along with your own sources. Note, that you need to preserve GL folder or manually fix includes in gl3w.c.

Second way. Create new project add all three files in it and compile as static library. Then link it to your application (or just compile it in command line or makefile, whatever).

Happy coding!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top