gameprogcpp / code

Game Programming in C++ Code
Other
1.01k stars 354 forks source link

A way to draw simple lines #23

Closed tannic1973 closed 5 years ago

tannic1973 commented 5 years ago

Hi I want to be able to draw some simple axis lines in the meshComponents. i have added an "AxisComponent" that works similar to MeshComponent. To be able to see if it draws anything, i set glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

My draw method looks like this: void AxisComponent::Draw(Shader* shader) { // Set the world transform shader->SetMatrixUniform("WorldTransform", Owner->GetWorldTransform()); glBegin(GL_TRIANGLES); glColor3f(1.0f, 1.0f, 0.0f); glVertex3d(0.0f, 0.0f, 0.0f); glVertex3d(500.0f, 500.0f, 500.0f); glVertex3d(0.0f, 500.0f, 500.0f); glEnd(); }

what do i do wrong?

chalonverse commented 5 years ago

glBegin, glColor3f, glVertex3d, and glEnd functions do not work with modern OpenGL using shaders. Those are all old functions that are largely deprecated.

If you want to draw lines, you'll need to make a vertex buffer and use glDrawArrays with the GL_LINES type. You also may want to change which shader it uses specifically for the line drawing.