在 FLTK 中使用 GLUT [重复]
Posted
技术标签:
【中文标题】在 FLTK 中使用 GLUT [重复]【英文标题】:Using GLUT in FLTK [duplicate] 【发布时间】:2014-11-27 14:09:10 【问题描述】:我的应用程序由常规的 FLTK 小部件(按钮等)和一个 OpenGL 窗口组成。我的意图是使用 GLUT 在这个 OpenGL 窗口中绘制。按照说明here:
您应该能够编译现有的 GLUT 源代码,包括 代替 。这可以通过编辑 源,通过将 -I 开关更改为编译器,或提供 从 GL/glut.h 到 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 时,程序正在正确编译。在更改标题以使用 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);
【问题讨论】:
【参考方案1】:这与 GLUT 无关。
所有这些函数都是 OpenGL 1.1 和特定于 Windows 的窗口系统 API (WGL) 的一部分。
要解决此问题,只需将 opengl32.lib
添加到您的库中即可。
但是,几乎所有这些功能都已被弃用,如果担心可移植性,您可能会考虑寻找 FLTKGL 的现代替代品。
【讨论】:
以上是关于在 FLTK 中使用 GLUT [重复]的主要内容,如果未能解决你的问题,请参考以下文章