Created
October 10, 2016 22:52
-
-
Save Samvid95/d8185d734c5e4c61ddf68ad00af9d69b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "glsupport.h" | |
#include <glut.h> | |
GLint program; | |
GLuint vertPostionVBO; | |
GLuint positionAttribute; | |
void display(void) { | |
glClear(GL_COLOR_BUFFER_BIT); | |
glUseProgram(program); | |
glBindBuffer(GL_ARRAY_BUFFER, vertPostionVBO); | |
glVertexAttribPointer(positionAttribute, 2, GL_FLOAT, GL_FALSE, 0, 0); | |
glEnableVertexAttribArray(positionAttribute); | |
glDrawArrays(GL_TRIANGLES, 0, 6); | |
glDisableVertexAttribArray(positionAttribute); | |
glutSwapBuffers(); | |
} | |
void init() { | |
glCullFace(GL_BACK); | |
glEnable(GL_CULL_FACE); | |
glEnable(GL_DEPTH_TEST); | |
glDepthFunc(GL_LESS); | |
glReadBuffer(GL_BACK); | |
glClearColor(0.2, 0.2, 0.2, 0.0); | |
program = glCreateProgram(); | |
readAndCompileShader(program, "vertex.glsl", "fragment.glsl"); | |
glUseProgram(program); | |
positionAttribute = glGetAttribLocation(program, "position"); | |
glGenBuffers(1, &vertPostionVBO); | |
glBindBuffer(GL_ARRAY_BUFFER, vertPostionVBO); | |
GLfloat sqVert[12] = { | |
-0.5f, -0.5f, | |
0.5f, -0.5f, | |
0.5f, 0.5f, | |
-0.5f, -0.5f, | |
-0.5f, 0.5f, | |
0.5f, 0.5f | |
}; | |
GLfloat cubeVerts[] = { | |
-0.5f, -0.5f, 0.0f, | |
0.5f, -0.5f, 0.0f, | |
0.5f, 0.5f, 0.0f, | |
-0.5f, -0.5f, 0.0f, | |
-0.5f, 0.5f, 0.0f, | |
0.5f, 0.5f, 0.0f | |
}; | |
glBufferData(GL_ARRAY_BUFFER, 18 * sizeof(GLfloat), cubeVerts, GL_STATIC_DRAW); | |
} | |
void reshape(int w, int h) { | |
glViewport(0, 0, w, h); | |
} | |
void idle(void) { | |
glutPostRedisplay(); | |
} | |
int main(int argc, char **argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB | GLUT_DEPTH); | |
glutInitWindowSize(500, 500); | |
glutCreateWindow("CS - 6533"); | |
glEnable(GL_DEPTH_TEST); | |
glewInit(); | |
glutDisplayFunc(display); | |
glutReshapeFunc(reshape); | |
glutIdleFunc(idle); | |
init(); | |
glutMainLoop(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment