• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# How to draw lines in Opengl ES 2.0?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1CPPNick  Members

Posted 10 June 2010 - 08:24 AM

How do I draw lines in OpenGL ES 2.0?
I have declared this: #include <GLES2/gl2.h>

but all of these functions seem to be undefined =(

glColor4f
glVertexPointer
glEnableClientState
glBegin
glEnd
glVertex3f

Using ES 1.1 is not an option. Can't I still draw lines in 2.0?

### #2karwosts  Members

Posted 10 June 2010 - 08:28 AM

I would assume it is the same way you draw triangles. You probably need a shader, plus some of these commands:

glEnableVertexAttribArray()
glVertexAttribPointer()
glDrawArrays()/glDrawElements()

### #3CPPNick  Members

Posted 10 June 2010 - 08:50 AM

That's what I am using for triangles, but I couldn't figure out how I would use that for lines.

I want to draw the edges(defined separately) over top of the scene.
after drawing out my polygons, would it go something like this?

glDisableVertexAttribArray(0);glDisableVertexAttribArray(1);glDisableVertexAttribArray(2);glEnableVertexAttribArray(3);glVertexAttribPointer(3, 3, GL_FLOAT, 0, 0, (void*)lVerts);glDrawArrays(GL_LINES, 0, number_of_edges);

and could I then just put one boolean in my shader to draw the lines white when true? or do I have to make a different shader for the lines?

### #4karwosts  Members

Posted 10 June 2010 - 09:32 AM

You've got a few options, you just want to make sure to use the GL_LINES enum for the glDraw command.

I would probably not want to mess with booleans, I think you want to avoid dynamic branching whenever possible.

How are you coloring your triangles? I would either just send the color with your vertices, or have a uniform that defines the draw color, or a separate shader.

glDisableVertexAttribArray(0);glDisableVertexAttribArray(1);glDisableVertexAttribArray(2);glEnableVertexAttribArray(3);

Regarding this, what do you expect this to do? The attrib array maps to an input variable in the shader, you shouldn't just be setting these to constant values.

You'll should have something like:
vert_attrib_index = glGetAttribLocation(shaderNumber, "myShaderVertexAttribute");color_attrib_index = glGetAttribLocation(shaderNumber, "myShaderColorAttribute");glEnableVertexAttribArray(vert_attrib_index);glEnableVertexAttribArray(color_attrib_index);

### #5CPPNick  Members

Posted 10 June 2010 - 09:57 AM

actually, I kept messing around with it, and got this to work:

glDisable(GL_DEPTH_TEST);glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, (void*)lVerts);glDrawArrays(GL_LINES, 0, objects[2].nEdges*2);

my only problem now is that I use textured triangles, so my lines end up being drawn in the last texture that I used, instead of a solid color =/

I could use gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); in the shader, but can I switch fragment shaders on the fly? or do I have to actually create a whole second shader program? this is what I was talking about with the boolean value. This is only for debugging purposes, so I don't care if I have to branch out and make it slow. I jus need my lines visible.
thanks again for the help

### #6karwosts  Members

Posted 10 June 2010 - 10:09 AM

Nah you have to switch programs if you want a new shader.

You can use the boolean switch if you like. (I don't remember if uniform bools exist, but if not you can just use an int).

### #7CPPNick  Members

Posted 10 June 2010 - 10:10 AM

ya. I don't want write a class for multiple shaders right now. Thanks for the help. I'll use the int.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.