本文介绍了带有OpenGL的C ++中的原始重启索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在学习OpenGl,并尝试实现有关原始重启索引如何工作的简单测试.无论我做什么尝试,g ++都会给我错误未定义对__glewPrimitiveRestartIndex的引用".

I'm just learning OpenGl and trying to implement a simple test of how the Primitive Restart Index works. No matter what I try, g++ gives me the error "undefined reference to `__glewPrimitiveRestartIndex'."

这是有问题的代码:

#include <GL/glew.h>
#include <GL/freeglut.h>

static GLfloat vertices[] = {0.0, 0.0, 0.0, 5.0, -5.0, 0.0,
0xffff, 0.0, -10.0, 5.0, -15.0, 6.0, -8.0};

void init(void)
{
    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex(0xffff);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, 0, vertices);
}

我承认我对使用g ++有点陌生,并且不完全了解g ++的切换和包含机制.我用来编译它的g ++命令如下: g ++ -o test test.cpp -lGL -lglut

I admit that I'm a bit new to using g++, and don't fully understand its switch and include mechanisms. The g++ command I'm using to compile it is as follows: g++ -o test test.cpp -lGL -lglut

在命令上附加"-lGLEW"后,程序会编译,但会给我一个段错误.删除行"glPrimitiveRestartIndex(0xffff);"将-lGLEW附加到compile命令后,从代码中进行编译和运行就不会出错(当然,没有原始的重新启动索引正常工作),但尝试时会出现相同的错误.

Upon appending "-lGLEW" to the command, the program compiles but hands me a segfault. Removing the line "glPrimitiveRestartIndex(0xffff);" from the code makes it compile and run without fault (of course, without the primitive restart index working) when -lGLEW is appended to the compile command, but hands the same error when trying without.

这使我相信,最初的问题是由于未包含-lGLEW导致的-因此,唯一剩下的问题是弄清楚为什么我会遇到段错误.我尝试使用0xffff以外的其他值,但问题仍然存在.

This leads me to believe that the initial problem results from not having included -lGLEW - so the only remaining issue is figuring out why I'm being handed a segfault. I've tried with different values other than 0xffff, but the problem remains.

推荐答案

在实际加载OpenGL函数之前,请勿调用它们.由于使用的是GLEW,因此应在调用GL函数之前使用GLEW的初始化例程.有关详细信息,请参见GLEW的文档.

You should not call OpenGL functions until you have actually loaded them. Since you're using GLEW, you should use GLEW's initialization routines before calling GL functions. See GLEW's documentation for details.

哦,这不是原始重启的工作方式.重新启动索引是 index ,而不是顶点位置.它应该出现在您的索引列表中,即您提供给glDrawElements的内容.如果没有索引列表并且使用glDrawArrays进行绘制,则不能使用原始重启.

Oh, and that's not how primitive restart works. The restart index is an index, not a vertex position. It should go in your list of indices, what you give to glDrawElements. If you don't have a list of indices and are drawing with glDrawArrays, you cannot use primitive restart.

这篇关于带有OpenGL的C ++中的原始重启索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:33