Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmupen64plus/mupen64plus-video-z64/src/rgl_glut.cpp
2 views
1
/*
2
* z64
3
*
4
* Copyright (C) 2007 ziggy
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* with this program; if not, write to the Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
**/
21
22
#include <string.h>
23
24
#include <SDL.h>
25
26
#include "rgl_glut.h"
27
28
#ifdef RGL_USE_GLUT
29
#include <GL/glui.h>
30
31
extern int screen_width, screen_height;
32
33
/** These are the live variables passed into GLUI ***/
34
int wireframe = 0;
35
int segments = 8;
36
int main_window;
37
38
static GLUI *glui;
39
40
static SDL_sem * commandSem;
41
static SDL_cond * commandCond;
42
static SDL_mutex * commandMutex;
43
static SDL_sem * commandFinishedSem;
44
static rglGlutCommand_f command, nextCommand;
45
46
/***************************************** myGlutIdle() ***********/
47
48
void myGlutIdle( )
49
{
50
// SDL_LockMutex(commandMutex);
51
// if (!SDL_CondWaitTimeout(commandCond, commandMutex, 1)) {
52
if (!SDL_SemWaitTimeout(commandSem, 1)) {
53
//if (!SDL_SemWait(commandSem)) {
54
//printf("receive a command\n");
55
if ( glutGetWindow() && glutGetWindow() != main_window )
56
glutSetWindow(main_window);
57
nextCommand = command;
58
command = 0;
59
glutPostRedisplay();
60
}
61
// SDL_UnlockMutex(commandMutex);
62
}
63
64
void myGlutTimer( int dummy )
65
{
66
67
/* According to the GLUT specification, the current window is
68
undefined during an idle callback. So we need to explicitly change
69
it if necessary */
70
if ( glutGetWindow() != main_window )
71
glutSetWindow(main_window);
72
73
glutPostRedisplay();
74
}
75
76
77
/**************************************** myGlutReshape() *************/
78
79
void myGlutReshape( int x, int y )
80
{
81
float xy_aspect;
82
83
xy_aspect = (float)x / (float)y;
84
glViewport( 0, 0, x, y );
85
86
// glMatrixMode( GL_PROJECTION );
87
// glLoadIdentity();
88
// glFrustum( -xy_aspect*.08, xy_aspect*.08, -.08, .08, .1, 15.0 );
89
90
glutPostRedisplay();
91
}
92
93
/***************************************** myGlutDisplay() *****************/
94
95
void myGlutDisplay( void )
96
{
97
if (nextCommand) {
98
nextCommand();
99
nextCommand = 0;
100
SDL_SemPost(commandFinishedSem);
101
}
102
103
//glutSwapBuffers();
104
105
//glutTimerFunc(1, myGlutTimer, 0);
106
}
107
108
109
/**************************************** main() ********************/
110
111
static int glutmain(int argc, char* argv[])
112
{
113
/****************************************/
114
/* Initialize GLUT and create window */
115
/****************************************/
116
117
glutInit(&argc, argv);
118
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
119
//glutInitWindowPosition( 50, 50 );
120
glutInitWindowSize( screen_width, screen_height );
121
122
main_window = glutCreateWindow( "z64gl" );
123
glutDisplayFunc( myGlutDisplay );
124
glutReshapeFunc( myGlutReshape );
125
126
/****************************************/
127
/* Here's the GLUI code */
128
/****************************************/
129
130
glui = GLUI_Master.create_glui( "GLUI" );
131
new GLUI_Checkbox( glui, "Wireframe", &wireframe );
132
(new GLUI_Spinner( glui, "Segments:", &segments ))
133
->set_int_limits( 3, 60 );
134
135
glui->set_main_gfx_window( main_window );
136
137
/* We register the idle callback with GLUI, *not* with GLUT */
138
GLUI_Master.set_glutIdleFunc( myGlutIdle );
139
//glutTimerFunc(1, myGlutTimer, 0);
140
141
glutMainLoop();
142
143
return EXIT_SUCCESS;
144
}
145
146
147
148
149
150
static SDL_Thread * thread;
151
152
int rglGlutThread(void * dummy)
153
{
154
int argc = 1;
155
char * argv[2] = { "z64gl", 0 };
156
157
glutmain(argc, argv);
158
159
thread = 0;
160
161
// in case of, but glutMainLoop never exits anyway
162
exit(0);
163
}
164
165
void rglGlutMinimizeWindow()
166
{
167
//glutDestroyWindow(main_window);
168
myGlutReshape(64, 64);
169
}
170
171
void rglGlutRecreateWindow()
172
{
173
int oldmain = main_window;
174
175
glutInitWindowSize( screen_width, screen_height );
176
main_window = glutCreateWindow( "z64gl" );
177
glutDisplayFunc( myGlutDisplay );
178
glutReshapeFunc( myGlutReshape );
179
180
glui->set_main_gfx_window( main_window );
181
/* We register the idle callback with GLUI, *not* with GLUT */
182
GLUI_Master.set_glutIdleFunc( myGlutIdle );
183
//glutTimerFunc(1, myGlutTimer, 0);
184
185
glutSetWindow(main_window);
186
187
glutDestroyWindow(oldmain);
188
}
189
190
void rglGlutCreateThread(int recreate)
191
{
192
if (!thread) {
193
commandSem = SDL_CreateSemaphore(0);
194
commandCond = SDL_CreateCond();
195
commandMutex = SDL_CreateMutex();
196
commandFinishedSem = SDL_CreateSemaphore(0);
197
198
thread = SDL_CreateThread(rglGlutThread, 0);
199
} else if (recreate)
200
rglGlutPostCommand(rglGlutRecreateWindow);
201
}
202
203
void rglGlutPostCommand(rglGlutCommand_f c)
204
{
205
command = c;
206
SDL_SemPost(commandSem);
207
// SDL_LockMutex(commandMutex);
208
// SDL_CondSignal(commandCond);
209
// SDL_UnlockMutex(commandMutex);
210
SDL_SemWait(commandFinishedSem);
211
}
212
213
void rglSwapBuffers()
214
{
215
glutSwapBuffers();
216
}
217
218
#endif
219
220