6

我试图从我的应用程序中更新我的着色器中的眼睛位置,但是当我尝试这个时我不断收到错误 1281。初始化后我没有问题,就在我随后尝试更新值时。这是我的代码:

void GraphicsObject::SendShadersDDS(char vertFile [], char fragFile [], char filename []) {

            char *vs = NULL,*fs = NULL;

            vert = glCreateShader(GL_VERTEX_SHADER);
            frag = glCreateShader(GL_FRAGMENT_SHADER);

            vs = textFileRead(vertFile);
            fs = textFileRead(fragFile);
            const char * ff = fs;
            const char * vv = vs;

            glShaderSource(vert, 1, &vv, NULL);
            glShaderSource(frag, 1, &ff, NULL);

            free(vs); free(fs);

            glCompileShader(vert);
            glCompileShader(frag);

            program = glCreateProgram();
            glAttachShader(program, frag);
            glAttachShader(program, vert);

            glLinkProgram(program);
            glUseProgram(program);

        LoadCubeTexture(filename, compressedTexture);

        GLint location = glGetUniformLocation(program, "tex");
        glUniform1i(location, 0);
        glActiveTexture(GL_TEXTURE0);

        EyePos = glGetUniformLocation(program, "EyePosition");

        glUniform4f(EyePos, EyePosition.X(),EyePosition.Y(), 
                                    EyePosition.Z(), 1.0);          
        DWORD bob = glGetError();
        //All is fine here
        glEnable(GL_DEPTH_TEST);

}

这是我调用来更新眼睛位置的函数:

void GraphicsObject::UpdateEyePosition(Vector3d& eyePosition){

glUniform4f(EyePos, eyePosition.X(),eyePosition.Y(), 
                                    eyePosition.Z(), 1.0);

DWORD bob = glGetError();
//bob equals 1281 after this call       

}

我现在尝试了几种更新变量的方法,这是最新的化身,感谢观看,欢迎所有评论。

更新:错误实际上并没有在这里发生,我的错是假设它是,当我绘制一些 spring 时错误实际上发生了:

for(int i = 0; i < 2; i++) {

        springs[i].Draw();

}

当我绘制第一个时它很好,但是在调用 glEnd() 以响应 glBegin(GL_LINE_STRIP) 的位置调用第二个时出现错误。很抱歉给您带来不便,因为这不是我发布的错误,但至少如果有人想知道如何更新统一变量,那么它就在这里。

4

1 回答 1

4

这很可能是由于 EyePos 无效。

如果将函数更改为以下内容会发生什么?

void GraphicsObject::UpdateEyePosition(Vector3d& eyePosition)
{
    EyePos = glGetUniformLocation(program, "EyePosition");
    glUniform4f(EyePos, eyePosition.X(),eyePosition.Y(), eyePosition.Z(), 1.0);

    DWORD bob = glGetError();
}

编辑:为了响应您的更新,glBegin/glEnd 的文档说如果模式设置为不可接受的值,您将收到错误 1280 (GL_INVALID_ENUM)。因此,您的问题是不支持 GL_LINE_STRIP。

GL_INVALID_OPERATION is generated if glBegin is executed between a glBegin and the corresponding execution of glEnd.

GL_INVALID_OPERATION is generated if glEnd is executed without being preceded by a glBegin.

GL_INVALID_OPERATION is generated if a command other than glVertex, glColor, glSecondaryColor, glIndex, glNormal, glFogCoord, glTexCoord, glMultiTexCoord, glVertexAttrib, glEvalCoord, glEvalPoint, glArrayElement, glMaterial, glEdgeFlag, glCallList, or glCallLists is executed between the execution of glBegin and the corresponding execution glEnd.

GL_INVALID_OPERATION 返回错误 1282 和 GL_INVALID_ENUM 1280 ...所以很大程度上取决于您得到的确切错误...

于 2010-03-25T09:38:36.323 回答