OpenGL glut库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenGL glut库相关的知识,希望对你有一定的参考价值。

编译glut实例报错:
1>glutmech.obj : error LNK2019: 无法解析的外部符号 ___glutCreateMenuWithExit@8,该符号在函数 _glutCreateMenu_ATEXIT_HACK@4 中被引用
1>glutmech.obj : error LNK2019: 无法解析的外部符号 ___glutInitWithExit@12,该符号在函数 _glutInit_ATEXIT_HACK@8 中被引用
1>glutmech.obj : error LNK2019: 无法解析的外部符号 ___glutCreateWindowWithExit@8,该符号在函数 _glutCreateWindow_ATEXIT_HACK@4 中被引用
怎么解决

参考技术A I have the folling files in the following locations: -

glut.h
glu.h
gl.h
C:\Program Files\Microsoft Visual Studio 8\VC\include\GL

glut.32.lib
C:\Program Files\Microsoft Visual Studio 8\VC\lib

glut32.dll
glu32.gll
C:\WINDOWS\system32

I make a new project (Win32 Console App).
Set the Additional Dependencies under
Project | Properties | Config Properties | Linker | Input
I have: -
opengl32.lib glu32.lib glut32.lib

This is basically what just about every site I look at tells me to do.
So I copy over some code that I know compiles and runs under my Dev C++ setup...
And it fails to compile with the following errors: -
1>main.obj : error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8

1>main.obj : error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4

This is didn't happen a little while ago, as I was trying to solve a previous problem. This was that when I tried to run a successfully compiled program, an error would say: -
The procedure entry point __glutInitWithExit could not be located in the dynamic link library glut32.dll

solution:

Try define the following line right before including the header, glut.h.

更新窗口显示 OpenGL/GLUT C++

【中文标题】更新窗口显示 OpenGL/GLUT C++【英文标题】:Update window display OpenGL/GLUT C++ 【发布时间】:2015-05-24 00:34:22 【问题描述】:

我有一个方法,我需要这个方法来显示病毒在使用 GLUT 的网络中的行为(这是我第一次使用图形库)。

我展示了许多连接它们的点和线。该程序运行良好,它完美地显示了网络的初始状态,但是在调用方法模拟后我无法找到更新显示的方法。

这些点会根据计算机的状态改变颜色,所以我需要一种方法来每 3 秒或类似的更新一次显示(网络图)。有任何想法吗?

我已经阅读了有关使用glutPostRedisplay() 或以某种方式使用glutIdleFunc() 的信息,但我不明白如何实现它。感谢您的帮助。

这是我的代码:(但这仅显示初始状态)

void Visualizador::visualizar(int cItr, int ios, double vsc, int vcf, double rc, double grc) 

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1280,720);
glutCreateWindow("Network initial state");
glutDisplayFunc(display); //display creates a number of points (computers) and lines (connections)
glutIdleFunc(display);
glutMainLoop();

for (int i = 0; i < cItr; i++)  //cItr: Number of times the state of the network will be updated
    ostringstream oss;
    oss << "State #" << i+1 << " of the network";
    string windowName = oss.str();
    const char* cstr = windowName.c_str();
    simulator.simulate(1, vsc, vcf, rc, grc); //this method can change which point is infected
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutSetWindowTitle(cstr);
    glutMainLoop();
    

【问题讨论】:

【参考方案1】:

经过大量阅读后,我发现完成我想要做的事情的唯一方法是擦除代码并将我的模拟方法放在显示函数中。以下是代码最终的工作方式:

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1280,720);
glutCreateWindow("Network initial state");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();

如您所见,我只留下了代码的顶部。我这样做的原因是因为 glutIdleFunc(display) 将被连续调用,所以如果我在每次 glutIdleFunc() 调用 display 时更改显示函数内部的网络状态(调用模拟),网络就会改变。我还必须将 glutPostRedisplay() 放在 glutIdleFunc() 的底部。调用 glutPostRedisplay() 会导致程序引发一个标志,指示需要重新绘制窗口,或者换句话说,需要更新显示。

尽管存在未知变量,但我还是包含了显示代码,因为它可能对某人有所帮助:

void Visualizador::display() 

if(v->displayCount <= Visualizador::cantIterac) 

    int contVertices = 0;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    for (int i = 0; i < Visualizador::v->grafo.cntVrt*2; i += 2) 
        if (Visualizador::v->grafo.obtEst(contVertices) == Grafo::S) 
            glColor3f(0.0, 1.0, 0.0);
        
        else 
            if (Visualizador::v->grafo.obtEst(contVertices) == Grafo::R) 
                glColor3f(0.5, 0.5, 0.5);
            
            else 
                glColor3f(1.0, 0.0, 0.0); //red
            
        
        glPointSize(5.8);
        glBegin(GL_POINTS);
        glVertex2f(arrPos[i], arrPos[i + 1]);
        contVertices++;
    
    glEnd();

    contVertices = 0;
    glLineWidth(1.6); //Ajusta el ancho de las lineas
    glColor3f(0.2, 1.0, 1.0); //Color blanco
    glBegin(GL_LINES); //empieza a dibujar lineas, cada dos llamadas a la funcion glVertex dibuja una sola linea
    for (int i = 0; i < Visualizador::v->grafo.cntVrt*2; i += 2) 
        int* adyVrt = Visualizador::v->grafo.obtAdy(contVertices);
        for (int j = 0; j < Visualizador::v->grafo.arrVrt[contVertices].lstAdy->obtCntAdy(); j++) 
            glVertex2f(arrPos[i], arrPos[i + 1]);
            glVertex2f(arrPos[adyVrt[j]*2], arrPos[(adyVrt[j]*2) + 1]);
        
        contVertices++;
    
    glEnd();
    glutSwapBuffers();

    if (v->displayCount < Visualizador::cantIterac)
    
        Sleep(500);

        v->simulador.simular(1,Visualizador::virusSpreadC, Visualizador::virusCheckFrec, Visualizador::recoveryC, Visualizador::gainResistance);

        ostringstream oss;
        oss << "State #" << v->displayCount+1 << " of the network";
        string windowName = oss.str();
        const char* cstr = windowName.c_str();
        glutSetWindowTitle(cstr);
        glutPostRedisplay();
    
    v->displayCount++;

else

   glutIdleFunc(NULL);


【讨论】:

以上是关于OpenGL glut库的主要内容,如果未能解决你的问题,请参考以下文章

OpenGL2.0及以上版本中gl,glut,glew,glfw,mesa等部件的关系

opengl中如何实现图象的缩放

Windows 上 Eclipse 中的 OpenGL 和 GLUT

转OPENGL基本API概述

VS2008中OpenGL的使用

如何在Qt中配置OpenGL