c++ - 在 FLTK 中使用 GLUT

标签 c++ opengl glut freeglut fltk

<分区>

我的应用程序由常规的 FLTK 小部件(按钮等)和一个 OpenGL 窗口组成。我的意图是使用 GLUT 在这个 OpenGL 窗口中绘制。按照说明 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.

我也做了同样的事情,但出现以下链接错误:

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

当我使用 FreeGLUT 时,程序编译正确。在更改 header 以使用 FLTK 的 GLUT 版本后,我遇到了这些问题。我正在使用 Microsoft Visual Studio 10 并添加了以下静态库作为“附加依赖项”:

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

我做错了什么?另外,如何使用 GLUT 在我的 Fl_Gl_Window 中绘制?

这是我的程序:

// 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);
}

最佳答案

这与 GLUT 无关。

所有这些函数都是 OpenGL 1.1 和特定于 Windows 的窗口系统 API (WGL) 的一部分。

要解决此问题,只需将 opengl32.lib 添加到您的库中即可。

然而,几乎所有这些功能都已弃用,如果考虑到可移植性,您可能会考虑寻找 FLTKGL 的现代替代品。

关于c++ - 在 FLTK 中使用 GLUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27172605/

相关文章:

c - OS X 的低级窗口 API

c++ - 使编译器/优化器能够制作更快的程序的编码实践

c++ - 默认和参数化构造函数

c++ - 带有 tinyobjloader 的 OpenGL 顶点数组对象

java - 将纹理绘制到帧缓冲区会扭曲纹理

c++ - 无法通过glGetBufferSubData获取缓冲区对象数据

c++ - 关于在任何计算机上以相同速度运行程序的问题

c - 过剩和使用纹理图集

c++ - 删除和释放 QGraphicsItem 类派生对象

c++ - 使用Bandicam库