Using GLUT in FLTK

1.1k views Asked by At

My application consists of regular FLTK widgets (buttons, etc.), and an OpenGL window. My intention is to use GLUT to draw in this OpenGL Window. As per instructions here:

You should be able to compile existing GLUT source code by including instead of . This can be done by editing the source, by changing the -I switches to the compiler, or by providing a symbolic link from GL/glut.h to FL/glut.H.

I have done the same but I get the following linking errors:

1>Main.obj : error LNK2001: unresolved external symbol __imp__glClear@4
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>Main.obj : error LNK2001: unresolved external symbol __imp__glClearColor@16
1>Main.obj : error LNK2001: unresolved external symbol __imp__glFlush@0
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glFlush@0
1>Main.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glReadBuffer@4
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glDrawBuffer@4
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glOrtho@48
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glViewport@16
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glGetIntegerv@8
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__wglSwapLayerBuffers@8
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glCopyPixels@20
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glRasterPos2i@8
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glRasterPos2i@8
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__glDisable@4
1>fltkgl.lib(Fl_Gl_Window.obj) : error LNK2001: unresolved external symbol __imp__wglRealizeLayerPalette@12
1>fltkgl.lib(Fl_Gl_Choice.obj) : error LNK2001: unresolved external symbol __imp__wglShareLists@8
1>fltkgl.lib(Fl_Gl_Choice.obj) : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
1>fltkgl.lib(Fl_Gl_Choice.obj) : error LNK2001: unresolved external symbol __imp__wglCreateLayerContext@8
1>fltkgl.lib(Fl_Gl_Choice.obj) : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
1>fltkgl.lib(Fl_Gl_Choice.obj) : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
1>fltkgl.lib(Fl_Gl_Device_Plugin.obj) : error LNK2001: unresolved external symbol __imp__glPopClientAttrib@0
1>fltkgl.lib(Fl_Gl_Device_Plugin.obj) : error LNK2001: unresolved external symbol __imp__glReadPixels@28
1>fltkgl.lib(Fl_Gl_Device_Plugin.obj) : error LNK2001: unresolved external symbol __imp__glPixelStorei@8
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glPixelStorei@8
1>fltkgl.lib(Fl_Gl_Device_Plugin.obj) : error LNK2001: unresolved external symbol __imp__glPushClientAttrib@4
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glListBase@4
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glGenLists@4
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glDeleteLists@8
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glCallLists@12
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__wglUseFontBitmapsW@16
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glRasterPos2f@8
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glEnd@0
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glVertex2i@8
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glBegin@4
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glColor3ub@12
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glIndexi@4
1>fltkgl.lib(gl_draw.obj) : error LNK2001: unresolved external symbol __imp__glDrawPixels@20
1>D:\Skunkworks\Snake3D\Snake3D\Release\Snake3D.exe : fatal error LNK1120: 35 unresolved externals

The program was compiling properly when I was using FreeGLUT. After changing headers to use FLTK's version of GLUT I am getting these problems. I am using Microsoft Visual Studio 10 and have added the following static libraries as 'Additional Depedencies':

freeglut.lib glew32.lib fltk.lib fltkgl.lib

What am I doing wrong? Also, how do I draw in my Fl_Gl_Window using GLUT?

Here is my program:

// Make the GUI here
#define WIN32
#include <GL/glew.h>
#include <FL/glut.H>
#include <FL/glu.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Color_Chooser.H>
#include <FL/Fl_Gl_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Button.H>

class Block
{
public:
    Block(int x, int y, int z)
    {
        xyz[0] = x;
        xyz[1] = y;
        xyz[2] = z;
    }

    int getX(){ return xyz[0];}
    int getY(){ return xyz[1];}
    int getZ(){ return xyz[2];}

    void setX(int x){ xyz[0]=x;}
    void setY(int y){ xyz[1]=y;}
    void setZ(int z){ xyz[2]=z;}

private:
    int xyz[3];
};

// Snake is an array blocks.
Block* snake;
// Mouse is a single block
Block* mouse;

class GlWindow : public Fl_Gl_Window
{
public:
    // Call back for draw
    void draw()
    {
        // Get the current state of the universe and draw it
        glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Clear the background of our window to red  
        glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)  
        glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations  

        //glutSolidCube(5);
        glFlush(); // Flush the OpenGL buffers to the window  
    }

    // To handle key-events
    void handle()
    {
    }

    // Constructor
    GlWindow(int X, int Y, int W, int H, const char* L=0): Fl_Gl_Window(X,Y,W,H,L)
    {
    }

};

void buildGUI(int argc, char** argv)
{
    // Main Window  
    Fl_Double_Window *window = new Fl_Double_Window(800,500);
    window->label("Snake3D");
    window->color(FL_LIGHT3);
    window->begin();

    // Menu Bar
    Fl_Menu_Bar* menubar = new Fl_Menu_Bar(0,0,800,30);
    menubar->color(FL_LIGHT3);
    menubar->down_color(fl_rgb_color(0,145,255));
    menubar->box(FL_THIN_UP_BOX);
    menubar->add("File/Exit");
    menubar->add("Help/About");

    // OpenGL Window
    GlWindow* gameWindow = new GlWindow(200,30,600,470);

    // Start Button
    Fl_Button* startButton = new Fl_Button(50,200,100,30,"Start");
    Fl_Button* pauseButton = new Fl_Button(50,300,100,30,"Pause");
    window->show();
    window->end();
    Fl::run();
}

int main(int argc, char ** argv)
{   
    // Build GUI
    buildGUI(argc,argv);
}
1

There are 1 answers

0
Andon M. Coleman On

This has nothing to do with GLUT.

All of those functions are part of OpenGL 1.1 and the Windows-specific window system API (WGL).

To fix this, just add opengl32.lib to your libraries.

Almost every one of those functions is deprecated, however, and you might consider looking for a modern alternative to FLTKGL if portability is a concern.