-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjectvis.cpp
60 lines (49 loc) · 1.61 KB
/
objectvis.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
#include "objectvis.h"
#include <GL/glew.h>
#include <GL/freeglut.h>
objectVis::~objectVis()
{
glDeleteBuffers(2,vbo);
glDeleteVertexArrays(1,&vao);
if (pData)
{
delete[] pData;
delete[] pIndices;
}
}
void objectVis::initGLBuffers(GLuint programId, const char* posName, const char* norName, const char* texName)
{
glGenVertexArrays( 1, &vao );
glBindVertexArray ( vao );
glGenBuffers ( 2, &vbo[0]);
glBindBuffer ( GL_ARRAY_BUFFER, vbo[0] );
glBufferData ( GL_ARRAY_BUFFER, dataCount*sizeof(VertexData), pData, GL_STATIC_DRAW );
glEnable(GL_ELEMENT_ARRAY_BUFFER);
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, vbo[1] );
glBufferData ( GL_ELEMENT_ARRAY_BUFFER, indicesCount*sizeof(unsigned int), pIndices, GL_STATIC_DRAW );
int loc = glGetAttribLocation(programId, posName);
if (loc>-1)
{
glVertexAttribPointer(loc,3,GL_FLOAT,GL_FALSE,sizeof(VertexData),(GLuint *)0);
glEnableVertexAttribArray (loc);
}
int loc2 = glGetAttribLocation(programId, norName);
if (loc2>-1)
{
glVertexAttribPointer(loc2,3,GL_FLOAT,GL_FALSE,sizeof(VertexData),(GLuint *)(0+sizeof(float)*3));
glEnableVertexAttribArray (loc2);
}
int loc3 = glGetAttribLocation(programId, texName);
if (loc3>-1)
{
glVertexAttribPointer(loc3,2,GL_FLOAT,GL_FALSE,sizeof(VertexData),(GLuint *)(0+sizeof(float)*6));
glEnableVertexAttribArray (loc3);
}
glBindVertexArray(0);
}
void objectVis::visualize()
{
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES,indicesCount,GL_UNSIGNED_INT,0);
glBindVertexArray(0);
}