Game Development Community

Draw a line with OpenGL?

by Entr0py · in Torque 2D Beginner · 10/30/2014 (5:49 pm) · 5 replies

I have searched documentation and forums for hours and hours and can't find anything.

What am I doing wrong?

glLineWidth(2.5); 
glColor3f(0.9f, 0.9f, 0.9f);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(15, 15, 0);
glEnd();

#1
10/30/2014 (5:54 pm)
That code is valid openGL code.

I wonder if it is with the way Torque renders? I haven't looked into the renderer much on either T2D or T3D, but I assume maybe its not being called in the right place and its getting cleared out or something before it ever submits to the graphics card?? Just a wild guess :/
#2
10/30/2014 (6:27 pm)
Oh I didn't have an onrender(). XD

It needs to be a child of another class that gets onrender() like GuiControl.
#3
10/31/2014 (6:22 am)
Yep that sounds about right. I assume that if you do not call it in onRender then Torque is flushing that call somewhere before submitting it to the graphics card. Good to know :D
#4
10/31/2014 (8:59 am)
As a rough summary: the game loop calls Canvas->renderFrame each loop and in that method onRender is called for the main content control, which is also cascaded down to all child GuiControls. The SceneWindow uses onRender to setup the OpenGL coord system, model view, and orthographic projection along with setting up a scene render state. It then calls the sceneRender method on all scene objects in the current scene. Those objects send render requests to the batch render system, which handles the rest of the OpenGL rendering process.

The scene also has a bunch of debug drawing functionality - you can look through the DebugDraw code for examples on drawing primitives as well.
#5
11/02/2014 (11:43 pm)
Most modern GPUs are more efficient drawing quads now. Most drivers actually draw very thin quads when drawing a line. So you might want to consider drawing quads so you can control the thickness of the line.

I ran into this when trying to draw music waves. I found the opengl lines too thin for what I wanted.