PDA

View Full Version : OpenGL 3.2 core profile: Drawing lines



Schnulla
08-08-2010, 07:57 AM
Hi,

to draw some simple lines can I just disable the
current active shader using glUseProgram(0);
thus enabling the fixed function pipeline and
then call glDrawArrays(GL_LINES,...)?

Something like this:

glBindBuffer(GL_ARRAY_BUFFER, VBOVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, VertexBuffer.size() * sizeof(Vec3), &VertexBuffer[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);

glDrawArrays(GL_LINES, 0, VertexBuffer.size());

I wonder which attribute index the "default shader" uses
for vertices and how to setup the colors that should be
used to render the lines (maybe there is also a default
color array attribute index that could be enabled?).

Help is really appreciated!

Alfonse Reinheart
08-08-2010, 10:18 AM
I wonder which attribute index the "default shader" uses
for vertices

None. Attribute indices are only used for actual shaders. If you are not using a shader, then you may not use generic attributes (ie: glVertexAttribPointer). You must use things like glVertexPointer, glColorPointer, etc.

Schnulla
08-08-2010, 02:28 PM
None. Attribute indices are only used for actual shaders. If you are not using a shader, then you may not use generic attributes (ie: glVertexAttribPointer). You must use things like glVertexPointer, glColorPointer, etc.

Ah ok but how can I use these deprecated functions
in a core profile context since they are not
allowed and therefore not defined in gl3.h?

Or does this mean drawing lines using the fixed
function pipeline in a core profile context is
not possible and instead one has to write an own
shader which is used in a glDrawArray(GL_LINES)
call? To be honest I have no clue if self written
shaders also work for GL_LINES or just for
GL_TRIANGLES. :o

Alfonse Reinheart
08-08-2010, 03:26 PM
Ah ok but how can I use these deprecated functions
in a core profile context since they are not
allowed and therefore not defined in gl3.h?

You cannot used fixed functionality at all in the core profile. So you can't possibly not be using shaders.


To be honest I have no clue if self written
shaders also work for GL_LINES or just for
GL_TRIANGLES.

Except for the tessellation and geometry shaders, shaders do not discriminate based on primitive type. Indeed, except for these kinds of shaders, shaders do not know what primitive type you are using.

Schnulla
08-09-2010, 04:41 AM
shaders do not discriminate based on primitive type. Indeed, except for these kinds of shaders, shaders do not know what primitive type you are using.

Ok thanks a lot, so a minimalist shader should
do the trick for GL_LINES :) Thank you!