1 /*
2 * Phlipple
3 * Copyright (C) Remigiusz Dybka 2011 <remigiusz.dybka@gmail.com>
4 *
5 Phlipple is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Phlipple is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifdef _WIN32
20 #include <windows.h>
21 #endif
22 #include "GL/glew.h"
23 #include <GL/gl.h>
24
25 #include "quadrenderer.h"
26
27 int quad_renderer_initialized = 0;
28
29 GLuint qvbos[2];
30
31 float verts[20] =
32 {
33 -.5f, .5f, 0,
34 -.5f, -.5f, 0,
35 .5f, -.5f, 0,
36 .5f, .5f, 0,
37 0, 0,
38 0, 1.0,
39 1.0f, 1.0f,
40 1.0f, 0
41 };
42
43 short ind[6] =
44 {
45 0, 1, 2,
46 0, 2, 3
47 };
48
49
quad_renderer_init()50 void quad_renderer_init()
51 {
52 if (quad_renderer_initialized)
53 return;
54
55 glGenBuffers(2, qvbos);
56
57 glBindBuffer(GL_ARRAY_BUFFER, qvbos[0]);
58 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts,
59 GL_STATIC_DRAW);
60
61 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, qvbos[1]);
62 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(ind),
63 ind, GL_STATIC_DRAW);
64
65 quad_renderer_initialized = 1;
66
67 }
68
quad_renderer_destroy()69 void quad_renderer_destroy()
70 {
71 if (!quad_renderer_initialized)
72 return;
73
74 glDeleteBuffers(2, qvbos);
75 }
76
quad_renderer_begin()77 void quad_renderer_begin()
78 {
79 glEnable(GL_TEXTURE_2D);
80 glEnableClientState(GL_VERTEX_ARRAY);
81 glDisableClientState(GL_COLOR_ARRAY);
82 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
83
84 glBindBuffer(GL_ARRAY_BUFFER, qvbos[0]);
85 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, qvbos[1]);
86
87 glVertexPointer(3, GL_FLOAT, 0, 0);
88 glTexCoordPointer(2, GL_FLOAT, 0, (void *)(12 * sizeof(float)));
89
90 }
91
render_quad()92 void render_quad()
93 {
94 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);
95 }
96