Path: blob/master/libmupen64plus/mupen64plus-video-z64/src/rgl_glut.cpp
2 views
/*1* z642*3* Copyright (C) 2007 ziggy4*5* This program is free software; you can redistribute it and/or modify6* it under the terms of the GNU General Public License as published by7* the Free Software Foundation; either version 2 of the License, or8* (at your option) any later version.9*10* This program is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13* GNU General Public License for more details.14*15* You should have received a copy of the GNU General Public License along16* with this program; if not, write to the Free Software Foundation, Inc.,17* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.18*19**/2021#include <string.h>2223#include <SDL.h>2425#include "rgl_glut.h"2627#ifdef RGL_USE_GLUT28#include <GL/glui.h>2930extern int screen_width, screen_height;3132/** These are the live variables passed into GLUI ***/33int wireframe = 0;34int segments = 8;35int main_window;3637static GLUI *glui;3839static SDL_sem * commandSem;40static SDL_cond * commandCond;41static SDL_mutex * commandMutex;42static SDL_sem * commandFinishedSem;43static rglGlutCommand_f command, nextCommand;4445/***************************************** myGlutIdle() ***********/4647void myGlutIdle( )48{49// SDL_LockMutex(commandMutex);50// if (!SDL_CondWaitTimeout(commandCond, commandMutex, 1)) {51if (!SDL_SemWaitTimeout(commandSem, 1)) {52//if (!SDL_SemWait(commandSem)) {53//printf("receive a command\n");54if ( glutGetWindow() && glutGetWindow() != main_window )55glutSetWindow(main_window);56nextCommand = command;57command = 0;58glutPostRedisplay();59}60// SDL_UnlockMutex(commandMutex);61}6263void myGlutTimer( int dummy )64{6566/* According to the GLUT specification, the current window is67undefined during an idle callback. So we need to explicitly change68it if necessary */69if ( glutGetWindow() != main_window )70glutSetWindow(main_window);7172glutPostRedisplay();73}747576/**************************************** myGlutReshape() *************/7778void myGlutReshape( int x, int y )79{80float xy_aspect;8182xy_aspect = (float)x / (float)y;83glViewport( 0, 0, x, y );8485// glMatrixMode( GL_PROJECTION );86// glLoadIdentity();87// glFrustum( -xy_aspect*.08, xy_aspect*.08, -.08, .08, .1, 15.0 );8889glutPostRedisplay();90}9192/***************************************** myGlutDisplay() *****************/9394void myGlutDisplay( void )95{96if (nextCommand) {97nextCommand();98nextCommand = 0;99SDL_SemPost(commandFinishedSem);100}101102//glutSwapBuffers();103104//glutTimerFunc(1, myGlutTimer, 0);105}106107108/**************************************** main() ********************/109110static int glutmain(int argc, char* argv[])111{112/****************************************/113/* Initialize GLUT and create window */114/****************************************/115116glutInit(&argc, argv);117glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );118//glutInitWindowPosition( 50, 50 );119glutInitWindowSize( screen_width, screen_height );120121main_window = glutCreateWindow( "z64gl" );122glutDisplayFunc( myGlutDisplay );123glutReshapeFunc( myGlutReshape );124125/****************************************/126/* Here's the GLUI code */127/****************************************/128129glui = GLUI_Master.create_glui( "GLUI" );130new GLUI_Checkbox( glui, "Wireframe", &wireframe );131(new GLUI_Spinner( glui, "Segments:", &segments ))132->set_int_limits( 3, 60 );133134glui->set_main_gfx_window( main_window );135136/* We register the idle callback with GLUI, *not* with GLUT */137GLUI_Master.set_glutIdleFunc( myGlutIdle );138//glutTimerFunc(1, myGlutTimer, 0);139140glutMainLoop();141142return EXIT_SUCCESS;143}144145146147148149static SDL_Thread * thread;150151int rglGlutThread(void * dummy)152{153int argc = 1;154char * argv[2] = { "z64gl", 0 };155156glutmain(argc, argv);157158thread = 0;159160// in case of, but glutMainLoop never exits anyway161exit(0);162}163164void rglGlutMinimizeWindow()165{166//glutDestroyWindow(main_window);167myGlutReshape(64, 64);168}169170void rglGlutRecreateWindow()171{172int oldmain = main_window;173174glutInitWindowSize( screen_width, screen_height );175main_window = glutCreateWindow( "z64gl" );176glutDisplayFunc( myGlutDisplay );177glutReshapeFunc( myGlutReshape );178179glui->set_main_gfx_window( main_window );180/* We register the idle callback with GLUI, *not* with GLUT */181GLUI_Master.set_glutIdleFunc( myGlutIdle );182//glutTimerFunc(1, myGlutTimer, 0);183184glutSetWindow(main_window);185186glutDestroyWindow(oldmain);187}188189void rglGlutCreateThread(int recreate)190{191if (!thread) {192commandSem = SDL_CreateSemaphore(0);193commandCond = SDL_CreateCond();194commandMutex = SDL_CreateMutex();195commandFinishedSem = SDL_CreateSemaphore(0);196197thread = SDL_CreateThread(rglGlutThread, 0);198} else if (recreate)199rglGlutPostCommand(rglGlutRecreateWindow);200}201202void rglGlutPostCommand(rglGlutCommand_f c)203{204command = c;205SDL_SemPost(commandSem);206// SDL_LockMutex(commandMutex);207// SDL_CondSignal(commandCond);208// SDL_UnlockMutex(commandMutex);209SDL_SemWait(commandFinishedSem);210}211212void rglSwapBuffers()213{214glutSwapBuffers();215}216217#endif218219220