Hi All
I am trying to put the below program together. All that it needs to do is display a triangle.
#include "Angel.h"
//----------------------------------------------------------------------------
void
init( void )
{
// sets the color that will be used when clearing the screen
glClearColor( 0.0, 0.0, 0.0, 0.0 );
vec4 vertexPositions[] =
{
0.75f, 0.75f, 0.0f, 1.0f,
0.75f, -0.75f, 0.0f, 1.0f,
-0.75f, -0.75f, 0.0f, 1.0f,
};
GLuint positionBufferObject;
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
GLuint program = InitShader( "vshader23.glsl", "fshader23.glsl" );
glUseProgram( program );
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray(loc);
// tell openGL how to interpret the array of data stored in buffer
// this implicitly refers to the buffer currently bound to GL_ARRAY_BUFFER
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
}
//----------------------------------------------------------------------------
void
display( void )
{
// clears the window, sets color to glClearColor()
glClear( GL_COLOR_BUFFER_BIT );
// rendering function
glDrawArrays(GL_TRIANGLES, 0, 3);
// glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
// GL_POINTS, tells the GPU we want the data to be used to display distinct points rather than other primitives such as lines or polygons
// glDrawArrays( GL_POINTS, 0, NumPoints ); // draw the points
// glFlush ensures that all the data are rendered as soon as possible
glFlush();
}
//----------------------------------------------------------------------------
void reshape (int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
}
//----------------------------------------------------------------------------
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
//----------------------------------------------------------------------------
void demo_menu(int id)
{
switch(id)
{
case 1:
exit(0);
break;
}
glutPostRedisplay();
}
int
main( int argc, char **argv )
{
glutInit( &argc, argv );
// use GLUT_DOUBLE to add in double buffering. Remember parameters are logically or'ed.
// GLUT_DEPTH is used for hidden surface removal.
glutInitDisplayMode( GLUT_RGBA | GLUT_SINGLE );
glutInitWindowSize( 600, 600 );
glutInitWindowPosition(100, 100);
glutCreateWindow( "Assignment 01" );
glewExperimental = GL_TRUE;
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutCreateMenu(demo_menu);
glutAddMenuEntry("quit", 1);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
#version 330
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}
Please help, it will be much appreciated. I am not sure where I am going wrong.