-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIInterface.cpp
More file actions
executable file
·88 lines (70 loc) · 2.59 KB
/
UIInterface.cpp
File metadata and controls
executable file
·88 lines (70 loc) · 2.59 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
86
87
88
#include "UIInterface.h"
#include <FL/Fl.H>
#include <GL/glu.h>
#include <FL/Fl_Widget.H>
UIInterface::UIInterface( )
{
}
UIInterface::~UIInterface()
{
}
void UIInterface::setup2DDrawing( const Color &colBackground, int width, int height )
{
glPushAttrib( GL_ALL_ATTRIB_BITS );
glClearColor( colBackground[0], colBackground[1], colBackground[2], 1.0f);
// No light needed for 2D drawing
glDisable( GL_LIGHT0 );
// Set up camera and viewport for 2D images
// Ensures that glVertex2d(x,y) will go to x,y on the screen
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable( GL_LIGHTING );
glDisable( GL_DEPTH );
// Clear the frame buffer (color is set to whatever glClearColor (DrawRoutines::setBackground) was set to
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void UIInterface::setup3DDrawing( const Color &colBackground, int width, int height, bool bOneLight )
{
//Save attributes
glPushAttrib( GL_ALL_ATTRIB_BITS );
glClearColor( colBackground[0], colBackground[1], colBackground[2], 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
// Normalizes normals
glEnable(GL_NORMALIZE);
// Setup a basic projective camera
// Will be overwritten by UIs that have cameras
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat) width /(GLfloat) height, 0.1, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if ( bOneLight == true ) {
// Make this light white
GLfloat colWhite[4] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat colGrey[4] = {0.2f, 0.2f, 0.2f, 1.0f};
// Last number zero forces this to be a directional light
GLfloat pos[4] = {0.1f, 0.1f, 1.0f, 0.0f};
// Set light color
glLightfv(GL_LIGHT0, GL_DIFFUSE , colWhite);
glLightfv(GL_LIGHT0, GL_SPECULAR , colWhite);
glLightfv(GL_LIGHT0, GL_AMBIENT , colGrey);
// Set light direction
glLightfv(GL_LIGHT0, GL_POSITION , pos );
//Enable light
glEnable(GL_LIGHT0);
}
// Clear the frame buffer (color is set to whatever glClearColor (DrawRoutines::setBackground) was set to
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void UIInterface::endDrawing()
{
// Return to previous attribute state
glPopAttrib();
}