Skip to main content
GameDev.net gamedev.net
🔒 Locked

Draw a line

Started by reaperrar Oct 29, 2011 at 6:20 AM 1 replies 2k views
Original Post
reaperrar
reaperrar
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.
V-man
V-man
What's the deal with your matrices? They are all mat3 instead of being mat4.
reaperrar
reaperrar
Making a 2D game, figured I didn't really need to used 4x4...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.