Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glDrawElements without using shader?

Tags:

opengl

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

like image 349
Yan Li Avatar asked Jul 09 '26 17:07

Yan Li


1 Answers

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

like image 104
Trax Avatar answered Jul 14 '26 13:07

Trax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!