Jump to content
  • Advertisement
Sign in to follow this  
reaperrar

OpenGL Draw a line

This topic is 2600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Using opengl 3.3 and shaders, trying to draw a line but I get nothing rendering to the scene. I have had successful results using textures for sprites. But I'm not sure why this isn't working. Here is my shader:

#version 330
// DefaultLine.vert

precision highp float;

uniform mat3 ProjectionMatrix;
uniform mat3 ViewMatrix;
uniform mat3 ModelMatrix;
uniform vec4 ColourIn;

in vec3 Position;

out vec4 ColourOut;

void main()
{
mat3 mvpMatrix = ProjectionMatrix * ViewMatrix * ModelMatrix;
vec3 pos = mvpMatrix * Position;

gl_Position.x = pos.x;
gl_Position.y = pos.y;
gl_Position.z = 0.0;
gl_Position.w = 1.0;

ColourOut = ColourIn;
}


#version 330
// DefaultLine.frag

precision highp float;

uniform sampler2D ColorMapSampler;

in vec4 ColourOut;

out vec4 FragColor;

void main()
{
FragColor = ColourOut;

//This does not work either...
//FragColor.r = 1.0;
//FragColor.g = 1.0;
// FragColor.b = 1.0;
// FragColor.a = 1.0;
}


I'm pretty noob when it comes to opengl, so this is probably a bad way to draw lines. I Bind the vertices b4 calling drawelements, the vertices are set up to be linewidth wide and linelength tall, so they should be fine.
If there is a better way to draw lines, I'm all ears.

EDIT: Appears the shader may not be the problem, tested it with my sprite class (taking out the texture relate stuff) and the it was drawing a white square where the sprite would have been. So now I'm not sure what could be the problem as the line and sprite classes are almost identical :(

EDIT: Solved it >< Staring at the page for hours will eventually fix the problem. 1 variable in the wrong place, almost identically named as the one that was meant to be there. ah well.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!