/
glcommon.h
59 lines (51 loc) · 1.24 KB
/
glcommon.h
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
#ifndef GLCOMMON_H
#define GLCOMMON_H
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/glew.h>
#include <GL/wglew.h>
#include "common.h"
#ifdef near
#undef near
#endif
#ifdef far
#undef far
#endif
#define GLERROR(DESC) \
{ \
GLenum err = glGetError(); \
if(err != GL_NO_ERROR) { \
cerr << "Error in " << DESC << ":" << endl; \
cerr << "\t>> No is: " << err << " String is: " << gluErrorString(err) << endl; \
assert(err == GL_NO_ERROR); \
} \
}
struct Camera {
float3 eye, center, up;
float fovy, near, far;
float rotx, roty;
void perspective_camera(int w,int h) {
float ratio = w / static_cast<float>(h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fovy,ratio,near,far);
/*gluLookAt(eye.x,eye.y,eye.z,
center.x,center.y,center.z,
up.x,up.y,up.z);*/
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(rotx,1.0,0.0,0.0); //rotate our camera on teh
glRotatef(roty,0.0,1.0,0.0);
glTranslatef(-eye.x, -eye.y, -eye.z);
//glLoadIdentity();
}
void orthogonal_camera(int w,int h) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,static_cast<float>(w),static_cast<float>(h),0.f,-1.f,1.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
};
#endif // GLCOMMON_H