PDA

View Full Version : What's wrong with this simple vertex buffer program?



abysswalker
09-05-2016, 12:14 PM
Hi.

I have a very small program that i hoped would draw a blue point at a coordinate i wanted. But it always draws at the middle of the screen. Can you tell what i'm missing?

Here is all of the code:



#include <GL/glew.h>
#include <GL/glut.h>


float vertices[][3]=
{
{0.5f ,0.5f,0.0f} //This is the coordinate that i want to draw.
};

void display();
int main(int argc, char* argv[])
{
glutInit(&argc , argv);
glutCreateWindow("Window");

GLenum res = glewInit();
if (res != GLEW_OK)
{
return 1;
}

glClearColor(255,0,0,0);

glPointSize(10.0f);


GLuint vbo = 0;
glGenBuffers (1, &vbo);

glBindBuffer (GL_ARRAY_BUFFER, vbo);
glBufferData (GL_ARRAY_BUFFER, 3*sizeof (float), vertices, GL_STATIC_DRAW);

glEnableVertexAttribArray (0);
glBindBuffer (GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL);

glutDisplayFunc(display);
glutMainLoop();


return 0;

}


void display() {

glClear(GL_COLOR_BUFFER_BIT);




glColor4f(0,0,255,255);

glDrawArrays (GL_POINTS, 0, 1);

}