help with shader please [SOLVED]

I am just trying to get a basic shader right, but it wont draw the line I want to see. What is wrong, what to fix?

#include <cstdlib>
#include <iostream>
#include <vector>

#include “glee/GLee.h”

#include “GL/glut.h”

#ifdef FREEGLUT

include “GL/freeglut_ext.h”

#endif // FREEGLUT

GLchar const* vs_source[] = {
“void main()”
“{”
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
“}”
};

//////////////////////////////////////////////////////////////////////////////
void DisplayFunc()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBegin(GL_LINES);

glVertex3f(-1, -1, -1);
glVertex3f(1, 1, -1);

glEnd();

glutSwapBuffers();
}

//////////////////////////////////////////////////////////////////////////////
void ReshapeFunc(int w, int h)
{
glViewport(0, 0, w, h);

glutPostRedisplay();
}

//////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);

glutCreateWindow(argv[0]);

glutDisplayFunc(DisplayFunc);
glutReshapeFunc(ReshapeFunc);

glOrtho(-1, 1, -1, 1, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

GLuint program;
GLuint shader;

shader = glCreateShader(GL_VERTEX_SHADER);

glShaderSource(shader, 1, vs_source, 0);
glCompileShader(shader);

GLint compiled;

glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);

if (!compiled)
{
GLint length;

glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
std::vector&lt;GLchar&gt; log;
log.resize(length);
glGetShaderInfoLog(shader, length, &length, &log[0]);
std::cerr &lt;&lt; &log[0] &lt;&lt; std::endl;
std::abort();

}
// else do nothing

program = glCreateProgram();
glAttachShader(program, shader);
glLinkProgram(program);

GLint linked;

glGetProgramiv(program, GL_LINK_STATUS, &linked);

if (!linked)
{
GLint length;

glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &length);
std::vector&lt;GLchar&gt; log(length);
glGetShaderInfoLog(shader, length, &length, &log[0]);
std::cerr &lt;&lt; &log[0] &lt;&lt; std::endl;
std::abort();

}
// else do nothing

glUseProgram(program);

glutMainLoop();

return EXIT_SUCCESS;
}

I’ve had to add gl_FrontColor = gl_Color; to the shader. Thanks for all the help :slight_smile:

Well, you only set up a custom vertex shader. That means you’re using the fixed-function fragment shader. The default fixed function fragment shader requires a vertex color to determine what color to draw things. Thus the reason your fix worked.