-1

I am following the OpenGL SuperBible 6th Edition and I have come upon a peculiar problem.

I have the following code rendering:

    const GLfloat color[] = { 0.0f, 0.2f, 0.0f, 1.0f };
    //crtime += 0.01;
    glClearBufferfv(GL_COLOR, 0, color);
    checkError();
    glUseProgram(program);
    checkError();
    GLfloat attrib[] = { (float)sin(crtime) * 0.5f, (float)cos(crtime) * 0.6f, 0.0f, 0.0f };
    glVertexAttrib4fv(0, attrib);
    checkError();
    glDrawArrays(GL_TRIANGLES, 0, 3);
    checkError();

checkError() is a simple function that checks if there's any OpenGL error and prints the gluErrorString for it if there is.

My OpenGL program consists of the following shaders:

vertex.glsl

#version 430 core

layout (location = 0) in vec4 offset;

void main(void) {
    const vec4 vertices[3] = vec4[3](vec4(0.25, -0.25, 0.5, 1.0), vec4(-0.25, -0.25, 0.5, 1.0), vec4(0.25, 0.25, 0.5, 1.0));
    gl_Position = vertices[gl_VertexID] + offset;
}

tessctrlshader.glsl

#version 430 core

layout (vertices = 3) out;

void main(void) {
    if(gl_InvocationID == 0) {
        gl_TessLevelInner[0] = 5.0;
        gl_TessLevelOuter[0] = 5.0;
        gl_TessLevelOuter[1] = 5.0;
        gl_TessLevelOuter[2] = 5.0;
    }
    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}

tessevalshader.glsl

#version 430 core

layout (triangles) in;

void main(void) {
    gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position);
}

fragment.glsl

#version 430 core

out vec4 color;

void main(void) { 
    color = vec4(0.0, 0.8, 1.0, 1.0);
}

Here's the initialization code (LCAShader() loads from a file and prints compilation errors if any)

program = glCreateProgram();
LCAShader("vertex.glsl", program, GL_VERTEX_SHADER);
LCAShader("tessctrlshader.glsl", program, GL_TESS_CONTROL_SHADER);
LCAShader("tessevalshader.glsl", program, GL_TESS_EVALUATION_SHADER);
LCAShader("fragment.glsl", program, GL_FRAGMENT_SHADER);
glLinkProgram(program);
glGenVertexArrays(1, &vertex_array_object);
glBindVertexArray(vertex_array_object);

Every time glDrawArrays is hit, OpenGL throws an GL_INVALID_OPERATION error. However, if I remove both of the tesselation shaders, this does not happen.

StelarCF
  • 48
  • 6
  • any compilation/link log output? – ratchet freak Sep 16 '14 at 09:30
  • Have you looked at the possible cases of GL_INVALID_OPERATION from DrawArrays? Have you looked at the debug output? – Bartek Banachewicz Sep 16 '14 at 09:42
  • @ratchetfreak: all the shaders compile with no warnings or errors. – StelarCF Sep 16 '14 at 10:40
  • @BartekBanachewicz I've looked [here](http://stackoverflow.com/questions/12017175/what-can-cause-gldrawarrays-to-generate-a-gl-invalid-operation-error). None of those cases apply to my program as far as I can tell (checked each one of them). I've also run a snippet of code to see if my resulting GLSL program is valid, which shows it is. – StelarCF Sep 16 '14 at 10:57

1 Answers1

1

I know it's an old thread but there is still no answer. In code form book author calls glDrawArrays with GL_TRIANGLES parameter. What you have to do is call glDrawArray(GL_PATCHES,0,3); in your render function.

Square
  • 43
  • 7