-
Notifications
You must be signed in to change notification settings - Fork 1
/
try.cpp
78 lines (56 loc) · 1.45 KB
/
try.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define GL3_PROTOTYPES 1
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include "debug.hpp"
#include "shaders.hpp"
#include "sdl_init.hpp"
#include "core/Buffer.hpp"
#include "core/Vector.hpp"
#include "gui/Window.hpp"
using namespace std;
int main(int argc, char *argv[])
{
Window win(512, 512, "tutorial");
glClearColor ( 1.0, 0.0, 0.0, 1.0 );
glClear ( GL_COLOR_BUFFER_BIT );
win.redraw();
win.delay(2000);
glClearColor ( 0.0, 1.0, 0.0, 1.0 );
glClear ( GL_COLOR_BUFFER_BIT );
win.redraw();
win.delay(2000);
glClearColor ( 0.0, 0.0, 1.0, 1.0 );
glClear ( GL_COLOR_BUFFER_BIT );
win.redraw();
win.delay(2000);
glewInit();
Program program;
program.addShader(Shader(GL_VERTEX_SHADER, "shader.vp"));
program.addShader(Shader(GL_FRAGMENT_SHADER, "shader.fp"));
program.link();
program.bind();
int loc = program.getAttributeLocation("vPosition");
program.enableAttributeArray(loc);
Vector vertices[3] = {
Vector(-1.0, -1.0, 0.0, 0.0),
Vector(1.0, -1.0, 0.0, 0.0),
Vector(0.0, 1.0, 0.0, 0.0)
};
GLfloat g_vertex_buffer_data[] = {
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
Buffer buf(GL_ARRAY_BUFFER);
buf.sendData(vertices, 3, false);
buf.bind();
program.setAttributeArray(loc, 3);
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
win.redraw();
win.delay(2000);
SDL_Quit();
return 0;
}