-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframework.cpp
More file actions
85 lines (63 loc) · 1.77 KB
/
framework.cpp
File metadata and controls
85 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<iostream>
#include<gl\glew.h>
#include<GL\GLU.h>
#include<gl\freeglut.h>
#include <algorithm>
#include <string>
#include <vector>
#include <stdio.h>
#include "framework.h"
GLuint theProgram, positionBufferObject,vao;
void InitializeProgram()
{
std::vector<GLuint> shaderList;
shaderList.push_back(Framework::LoadShader(GL_VERTEX_SHADER,"VS1.txt"));
shaderList.push_back(Framework::LoadShader(GL_FRAGMENT_SHADER,"FS2.txt"));
theProgram = Framework::CreateProgram(shaderList);
}
const float 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,
};
void InitializeVertexBuffer()
{
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void display()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(theProgram);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glUseProgram(0);
glutSwapBuffers();
}
void init()
{
glewInit();
InitializeProgram();
InitializeVertexBuffer();
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
}
int main(int agrc,char **agrv)
{
glutInit(&agrc,agrv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); //for animation programs GLUT_DOUBLE , GLUT_DEPTH for 3d apps
glutInitWindowSize(500,500); //screen resolution (width,height)
glutCreateWindow("shader");
glutInitWindowPosition(50,25);
glutDisplayFunc(display); //display function
init(); //put all initialization commands in this funtion
glutMainLoop();
return 0;
}