-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindow.cpp
133 lines (96 loc) · 2.67 KB
/
window.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "window.hpp"
#include "stdafx.h"
#include <GL/freeglut_std.h>
#include <GL/freeglut_ext.h>
using namespace view;
Window::Window( int width, int height, const std::string& name )
{
_name = name;
_width = width;
_height = height;
glutInitWindowSize(_width, _height );
_glut_win_id = glutCreateWindow(name.c_str());
glutSetWindowData(this);
glutDisplayFunc(glutDisplay);
glutKeyboardFunc(glutKeyboard);
glutReshapeFunc(glutReshape);
//glutMainLoop(); in die glut_engine.cpp :: run() verschoben.
}
int Window::id() const
{
return this->_glut_win_id;
}
unsigned int Window::width() const
{
return this->_width;
}
unsigned int Window::height() const
{
return this->_height;
}
// request window redisplay
void Window::invalidate()
{}
bool Window::display()
{
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
printf("Window id: %d, witdh: %d, heigth: %d\n",
this->id(),
this->width(),
this->height()
);
return true;
}
void Window::reshape()
{
//nachschauen, was das tut!
glViewport(0,0,width(),height());
}
void Window::keyboard(unsigned int key)
{
if(key == 113) {
std::printf("destroyed!!\n");
glutDestroyWindow(_glut_win_id);
glutLeaveMainLoop();
}
}
// make sure this Window is the current GLUT Window
void Window::ensureCurrent() const
{
glutSetWindow(this->_glut_win_id);
}
void Window::glutDisplay()
{
Window * ptr = static_cast<Window*>(::glutGetWindowData());
if( ptr != nullptr) {
if (ptr->id() != 0) {
ptr->ensureCurrent();
glutSwapBuffers();
if(ptr->display())
glutPostRedisplay();
} else std::cerr << "id ist 0!" << std::endl;
} else std::cerr<< "nullptr in glutDisplay!" << std::endl;
}
void Window::glutReshape( int width, int height )
{
Window * ptr = static_cast<Window*>(::glutGetWindowData());
if( ptr != nullptr) {
if (ptr->id() != 0) {
ptr->ensureCurrent();
ptr->setHeight(height);
ptr->setWidth(width);
ptr->reshape();
} else std::cerr << "id ist 0!" << std::endl;
} else std::cerr << "nullptr in glutReshape!" << std::endl;
}
void Window::glutKeyboard( unsigned char glut_key, int mouse_x, int mouse_y )
{
Window * ptr = static_cast<Window*>(::glutGetWindowData());
if( ptr != nullptr) {
if (ptr->id() != 0) {
ptr->ensureCurrent();
ptr->keyboard(glut_key);
} else std::cerr << "id ist 0!" << std::endl;
} else std::cerr << "nullptr in glutKey!" << std::endl;
}