Yan  Li
Yan Li

Reputation: 431

glDrawElements without using shader?

My question is can I use glDrawElements without using shader?

I generate my vbo like the following:

    glGenBuffers(1, &vertexId_);
    glBindBuffer(GL_ARRAY_BUFFER, vertexId_);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*((tess.x + 1) * (tess.y + 1)), &pVertex[0].p.x, GL_STATIC_DRAW);


    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *) vOffset_);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *) nOffset_);
    glEnableVertexAttribArray(2);
    glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *) tOffset_);

    glGenBuffers(1, &indexId_);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexId_);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned short)*idxCount_, &pIndices[0], GL_STATIC_DRAW);

    glBindVertexArray(0);

So the question is can I just use glDrawElements without binding any shaders to draw? I'm using GL 4.0

Upvotes: 3

Views: 1161

Answers (1)

Trax
Trax

Reputation: 1910

There is not fixed pipeline in OpenGL 4.0, you need shaders to tell what to do with that data (vertexes) you are sending to the GPU.

There are many resources on how to start with shaders, for example this one: http://nehe.gamedev.net/article/glsl_an_introduction/25007/

EDIT: As others pointed below this is not entirely true. You can use a compatibility profile and use the fixed pipeline if it is supported. http://www.opengl.org/registry/doc/glspec40.compatibility.20100311.pdf

Upvotes: 5

Related Questions