Hello,
I have this following code
#define GLEW_STATIC
#include <stdio.h>
#include <gl/glew.h>
#include <glfw.h>
#define BUFFER_OFFSET(offset)((char*)NULL+offset)
void init(void)
{
int glewinitialize;
float aspect_ratio;
glClearColor(0.0,0.0,0.0,0.0);
glShadeModel(GL_FLAT);
glewinitialize=glewInit();
if(glewinitialize==GLEW_OK)
{
printf("GLEW is available
");
}
//glViewport(0,0,640,480);
}
void GLFWCALL reshape(int width,int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)width,0.0,(GLdouble)height);
}
void display(void)
{
GLuint buffers[3];
GLfloat vertices[13][2]={{200,350},{230,300},{200,250},
{170,300},{230,200},{200,150},{170,200},{250,280},{300,250},{250,220},{150,280},{100,250},{150,220}};
GLfloat colors[4][3]={{1.0,0.0,0.0},{1.0,1.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}};
GLuint indices[4][4]={{0,1,2,3},{2,4,5,6},{2,7,8,9},{2,10,11,12}};
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glGenBuffers(3,buffers);
glBindBuffer(GL_ARRAY_BUFFER,buffers[0]);
glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2,GL_FLOAT,0,BUFFER_OFFSET(0));
glBindBuffer(GL_ARRAY_BUFFER,buffers[1]);
glBufferData(GL_ARRAY_BUFFER,sizeof(colors),colors,GL_STATIC_DRAW);
glColorPointer(3,GL_FLOAT,0,BUFFER_OFFSET(0));
glEnableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buffers[2]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(indices),indices,GL_STATIC_DRAW);
glDrawElements(GL_QUADS,16,GL_UNSIGNED_INT,BUFFER_OFFSET(0));
//glDrawArrays(GL_QUADS,0,16);
glfwSwapBuffers();
}
int main(int argc,char** argv)
{
int wndstate,wndopenstate;
wndstate=glfwInit();
if(wndstate==1)
{
wndopenstate=glfwOpenWindow(640,480,0,0,0,0,4,0,GLFW_WINDOW);
if(wndopenstate==0)
{
glfwTerminate();
}
else
{
glfwSetWindowTitle("Hello Opengl");
glfwSetWindowPos(30,30);
init();
glfwSetWindowSizeCallback(reshape);
while(1)
{
display();
if(glfwGetKey(GLFW_KEY_ESC))
{
glfwTerminate();
}
}
}
}
glfwTerminate();
return 0;
}
I have attached two images of the expected output and the output which i got .
I want the 4 quads in the expectedoutput.png to have different colors but the output which i got is only one quad with blue color(outputwithcolorpointer.png).
where is the mistake?
-swetha