⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ggiglut.c

📁 mesa-6.5-minigui源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ************************************************************************** * ggiglut.c * ************************************************************************** *  * Copyright (C) 1998 Uwe Maurer - uwe_maurer@t-online.de  * Copyright (C) 1999 James Simmons * Copyright (C) 1999 Jon Taylor * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *  * ************************************************************************** * To-do: * - Make everything use the portable ggi_* types *  */#define BUILDING_GGIGLUT#define WIDTH	640#define HEIGHT	480#define GRAPHTYPE_RGB	GT_16BIT#define GRAPHTYPE_INDEX	GT_8BIT/*************************************************************************/#include <GL/gl.h>#include <GL/glu.h>#include <GL/glut.h>#include <stdio.h>#include <stdarg.h>#include <string.h>#include "GL/ggimesa.h"#include "debug.h"#include <ggi/ggi.h>#include <ggi/gii.h>int _ggiglutDebugSync = 0;uint32 _ggiglutDebugState = 0;char *__glutProgramName = "GGI";static ggi_visual_t __glut_vis;static ggi_mesa_context_t __glut_ctx;//static int __glut_width = WIDTH;//static int __glut_height = HEIGHT;//static ggi_graphtype __glut_gt_rgb = GRAPHTYPE_RGB;//static ggi_graphtype __glut_gt_index = GRAPHTYPE_INDEX;static int __glut_width = GGI_AUTO;static int __glut_height = GGI_AUTO;static ggi_graphtype __glut_gt_rgb = GT_AUTO;static ggi_graphtype __glut_gt_index = GT_8BIT;static int __glut_init = GL_FALSE;static int mousex = WIDTH / 2;static int mousey = HEIGHT / 2;static int mouse_moved = GL_FALSE;static int mouse_down = GL_FALSE;static int mouse_showcursor = GL_FALSE;static void (*__glut_reshape)(int, int);static void (*__glut_display)(void);static void (*__glut_idle)(void);static void (*__glut_keyboard)(unsigned char, int, int);static void (*__glut_special)(int, int, int);static void (*__glut_mouse)(int, int, int, int);static void (*__glut_motion)(int, int);static void (*__glut_passive_motion)(int, int);static void (*__glut_visibility)(int);static unsigned int __glut_mode = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH;static int __glut_mod_keys = 0;static int __glut_redisplay = GL_FALSE;/* Menu */static int __glut_menubutton = -1;static int __glut_menuactive = GL_FALSE;#define MAX_ENTRIES	64typedef struct menu_s{	char *label[MAX_ENTRIES];	int value[MAX_ENTRIES];	struct menu_s * submenu[MAX_ENTRIES];	void (*func)(int);			int max_strlen;	int num_entries;} menu_t;static menu_t *mainmenu;static menu_t *curmenu;static menu_t *activemenu;void glutInit(int *argc, char **argv){	ggi_graphtype gt;	int i, k;	char *str;		GGIGLUTDPRINT_CORE("glutInit() called\n");	#define REMOVE  {for (k=i;k<*argc-1;k++) argv[k]=argv[k+1];  \				(*argc)--; i--; }	if (__glut_init) return;	        str = getenv("GGIGLUT_DEBUG");	if (str != NULL) {		_ggiglutDebugState = atoi(str);		fprintf(stderr, "Debugging=%d\n", _ggiglutDebugState);		GGIGLUTDPRINT_CORE("Debugging=%d\n", _ggiglutDebugState);	}		str = getenv("GGIGLUT_DEBUGSYNC");	if (str != NULL) {		_ggiglutDebugSync = 1;	}	if (argc && argv)	{		for (i = 1; i < *argc; i++)		{			if (strcmp(argv[i], "-mouse") == 0)			{				mouse_showcursor = GL_TRUE;					REMOVE;			}			else			if (strcmp(argv[i], "-bpp") == 0 && (i + 1) < (*argc))			{				switch(atoi(argv[i + 1]))				{					case 4: gt = GT_4BIT; break;					case 8: gt = GT_8BIT; break;					case 15: gt = GT_15BIT; break;					case 16: gt = GT_16BIT; break;					case 24: gt = GT_24BIT; break;					case 32: gt = GT_32BIT; break;					default:					ggiPanic("\"%s\" bits per pixel?\n", argv[i+1]);				}				__glut_gt_rgb = __glut_gt_index = gt;				REMOVE;				REMOVE;			} 			else			if (strcmp(argv[i], "-size") == 0 && (i + 2) < (*argc))			{				__glut_width = atoi(argv[i + 1]);				__glut_height = atoi(argv[i + 2]);				REMOVE;				REMOVE;				REMOVE;			}		}	}		if (ggiInit() < 0)	{		ggiPanic("ggiInit() failed!\n");	}	__glut_init = GL_TRUE;#undef REMOVE}void glutInitWindowPosition(int x, int y){	GGIGLUTDPRINT_CORE("glutInitWindowPosition() called\n");}void glutInitWindowSize(int x, int y){	GGIGLUTDPRINT_CORE("glutInitWindowsSize() called\n");}void glutFullScreen(void){	GGIGLUTDPRINT_CORE("glutFullScreen() called\n");}void glutInitDisplayMode(unsigned int mode){	GGIGLUTDPRINT_CORE("glutInitDisplayMode() called\n");		__glut_mode = mode;}void glutInitDisplayString(const char *string){	GGIGLUTDPRINT_CORE("glutInitDisplayString(%s) called\n", string);}int glutCreateWindow(const char *title){	ggi_graphtype gt;	ggi_mode mode = 	{		1,		{ GGI_AUTO, GGI_AUTO },		{ GGI_AUTO, GGI_AUTO },		{ 0, 0 },		GT_AUTO,		{ GGI_AUTO, GGI_AUTO }	};	int frames;	int rgb;	int err;	GGIGLUTDPRINT_CORE("glutCreateWindow() called\n");		if (!__glut_init) 	  glutInit(NULL, NULL);	GGIGLUTDPRINT("GGIGLUT: %s\n", title);	rgb = !(__glut_mode & GLUT_INDEX);	frames = (__glut_mode & GLUT_DOUBLE) ? 2 : 1;		gt = (rgb) ? __glut_gt_rgb : __glut_gt_index;		__glut_vis = ggiOpen(NULL);	if (__glut_vis == NULL) 	{	  ggiPanic("ggiOpen() failed!\n");	  /* return GL_FALSE; */	}		ggiSetFlags(__glut_vis, GGIFLAG_ASYNC);		ggiCheckMode(__glut_vis, &mode);		err = ggiSetMode(__glut_vis, &mode);	if (err < 0) 	{	  ggiPanic("Can't set graphic mode!\n");	  /* return GL_FALSE; */	}		if (ggiMesaExtendVisual(__glut_vis, GL_FALSE, GL_FALSE, 	                        16, 0, 0, 0, 0, 0, 1) < 0) 	{		ggiPanic("GGIMesaSetVisual failed!\n");	}		__glut_ctx = ggiMesaCreateContext(__glut_vis);		if (__glut_ctx == NULL) 	  ggiPanic("Can't create mesa-context\n");	ggiGetMode(__glut_vis, &mode);		__glut_width = mode.visible.x;	__glut_height = mode.visible.y;		mousex = mode.visible.x / 2;	mousey = mode.visible.y / 2;		ggiMesaMakeCurrent(__glut_ctx, __glut_vis);		if (__glut_reshape) 	  __glut_reshape(__glut_width, __glut_height);		return GL_TRUE;}void glutReshapeFunc(void (*func)(int, int)){	GGIGLUTDPRINT_CORE("glutReshapeFunc() called\n");		__glut_reshape = func;	if (__glut_vis && __glut_reshape) 	  __glut_reshape(__glut_width, __glut_height);}void glutKeyboardFunc(void (*keyboard)(unsigned char key, int x, int y)){	GGIGLUTDPRINT_CORE("glutKeyBoardFunc() called\n");	__glut_keyboard = keyboard;}int glutGetModifiers(void){	GGIGLUTDPRINT_CORE("glutGetModifiers() called\n");	return __glut_mod_keys;}void glutEntryFunc(void (*func)(int state)){	GGIGLUTDPRINT_CORE("glutEntryFunc() called\n");}void glutVisibilitFunc(void (*func)(int state)){	GGIGLUTDPRINT_CORE("glutVisibilityFunc() called\n");}void glutTimerFunc(unsigned int millis, void (*func)(int value), int value){	GGIGLUTDPRINT_CORE("glutTimerFunc() called\n");}void glutMenuStateFunc(void (*func)(int state)){	GGIGLUTDPRINT_CORE("glutMenuStateFunc() called\n");}int glutGet(GLenum type){	GGIGLUTDPRINT_CORE("glutGet() called\n");		switch(type)	{		case GLUT_WINDOW_X:			return 0;		case GLUT_WINDOW_Y:		return 0;		case GLUT_WINDOW_WIDTH:		return __glut_width;		case GLUT_WINDOW_HEIGHT:		return __glut_height;		case GLUT_MENU_NUM_ITEMS:		if (curmenu) 		  return curmenu->num_entries;		else 		  return 0;		default:		GGIGLUTDPRINT("glutGet: unknown type %i\n", type);	}	return 0;}void glutSpecialFunc(void (*special)(int key, int x, int y)){	GGIGLUTDPRINT_CORE("glutSpecialFunc() called\n");		__glut_special=special;}void glutDisplayFunc(void (*disp)(void)){	GGIGLUTDPRINT_CORE("glutDisplayFunc() called\n");	__glut_display=disp;}void glutSetColor(int index, GLfloat red, GLfloat green, GLfloat blue){	ggi_color c;	GLfloat max;  	GGIGLUTDPRINT_CORE("glutSetColor() called\n");		if (red > 1.0) red = 1.0;	if (red < 0.0) red = 0.0;	if (green > 1.0) green = 1.0;	if (green < 0.0) green = 0.0;	if (blue > 1.0) blue = 1.0;	if (blue < 0.0) blue = 0.0;  	max = (float)((1 << GGI_COLOR_PRECISION) - 1);		c.r = (int)(max * red);	c.g = (int)(max * green);	c.b = (int)(max * blue);	ggiSetPalette(__glut_vis, index, 1, &c);}void glutPostRedisplay(void){	GGIGLUTDPRINT_CORE("glutPostRedisplay() called\n");	__glut_redisplay = GL_TRUE;}void glutPostWindowRedisplay(int win){	GGIGLUTDPRINT_CORE("glutPostWindowRedisplay() called\n");		__glut_redisplay = GL_TRUE;}void glutSwapBuffers(void){	GGIGLUTDPRINT_CORE("glutSwapBuffers() called\n");	ggiMesaSwapBuffers();}void glutIdleFunc(void (*idle)(void)){	GGIGLUTDPRINT_CORE("glutIdleFunc() called\n");		__glut_idle = idle;}static void keyboard(ggi_event *ev){	int sym;	int modifer = 0, key = 0;  	GGIGLUTDPRINT_CORE("keyboard() called\n");		sym = ev->key.sym;  	modifer = ev->key.modifiers;	if (modifer == GII_KM_SHIFT)	  __glut_mod_keys |= GLUT_ACTIVE_SHIFT;	if (modifer == GII_KM_CTRL)	  __glut_mod_keys |= GLUT_ACTIVE_CTRL;	if (modifer == GII_KM_ALT)	  __glut_mod_keys |= GLUT_ACTIVE_ALT;	/* if (__glut_special && key) __glut_special(GII_KTYP(key),0,0); */  	if (__glut_keyboard) //	  __glut_keyboard(GII_UNICODE(sym), 0, 0);	  __glut_keyboard(sym, 0, 0);}static void mouseabs(ggi_event *ev){	int oldx = mousex;	int oldy = mousey;  	mousex = ev->pmove.x;	mousey = ev->pmove.y;  	if (mousex < 0) mousex = 0;	if (mousey < 0) mousey = 0;	if (mousex >= __glut_width) mousex = __glut_width - 1;	if (mousey >= __glut_height) mousey = __glut_height - 1;		if (mousex != oldx || mousey != oldy) mouse_moved = GL_TRUE;}static void mouse(ggi_event *ev){	int oldx = mousex;	int oldy = mousey;  	GGIGLUTDPRINT_CORE("mouse() called\n");		mousex += ev->pmove.x >> 1;	mousey += ev->pmove.y >> 1;		if (mousex < 0) mousex = 0;	if (mousey < 0) mousey = 0;	if (mousex >= __glut_width) mousex = __glut_width - 1;	if (mousey >= __glut_height) mousey = __glut_height - 1;		if (mousex != oldx || mousey != oldy) mouse_moved = GL_TRUE;  }static void showmenu(void);static int clickmenu(void);static void updatemouse(void);static void drawmouse(void);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -