diff options
author | Brian Paul <[email protected]> | 2001-08-20 16:07:10 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2001-08-20 16:07:10 +0000 |
commit | 976c26ca34f2ae8cc6f8b9f9b091efeba1311a94 (patch) | |
tree | 58022fef5a3d99ae764c0869cd151c4aa1949a7a | |
parent | 60174c1aef7c6650a800f16f103a4f9ed2d1004e (diff) |
WindML driver (Stephane Raimbault)
-rw-r--r-- | docs/README.WINDML | 144 | ||||
-rw-r--r-- | include/GL/uglglutshapes.h | 45 | ||||
-rw-r--r-- | include/GL/uglmesa.h | 322 | ||||
-rw-r--r-- | progs/windml/Makefile.ugl | 68 | ||||
-rw-r--r-- | progs/windml/readtex.c | 365 | ||||
-rw-r--r-- | progs/windml/uglaccum.c | 240 | ||||
-rw-r--r-- | progs/windml/uglalldemos.c | 98 | ||||
-rw-r--r-- | progs/windml/uglbounce.c | 268 | ||||
-rw-r--r-- | progs/windml/uglcube.c | 253 | ||||
-rw-r--r-- | progs/windml/ugldrawpix.c | 429 | ||||
-rw-r--r-- | progs/windml/uglflip.c | 219 | ||||
-rw-r--r-- | progs/windml/uglgears.c | 422 | ||||
-rw-r--r-- | progs/windml/uglicotorus.c | 311 | ||||
-rw-r--r-- | progs/windml/uglline.c | 270 | ||||
-rw-r--r-- | progs/windml/uglolympic.c | 474 | ||||
-rw-r--r-- | progs/windml/uglpoint.c | 266 | ||||
-rw-r--r-- | progs/windml/uglstencil.c | 233 | ||||
-rw-r--r-- | progs/windml/uglteapot.c | 290 | ||||
-rw-r--r-- | progs/windml/ugltexcube.c | 460 | ||||
-rw-r--r-- | progs/windml/ugltexcyl.c | 399 | ||||
-rw-r--r-- | progs/windml/wrs_logo.bmp | bin | 0 -> 196662 bytes | |||
-rw-r--r-- | src/glu/mesa/Makefile.ugl | 96 | ||||
-rw-r--r-- | src/mesa/main/Makefile.ugl | 367 |
23 files changed, 6039 insertions, 0 deletions
diff --git a/docs/README.WINDML b/docs/README.WINDML new file mode 100644 index 00000000000..a227d42b4db --- /dev/null +++ b/docs/README.WINDML @@ -0,0 +1,144 @@ + + WindML Driver for Mesa 3.5 + + +Requirements +------------ + +Tornado 2 + WindML, Cumulative Patchs are recommended. + +I suppose you have a valid WindML installation. Double buffer hardware +gives better performance than double buffer software so if you can +compile your WindML driver with this option, just do it. I/O +redirection is adviced in target server. + +Tested on +--------- + +During the development, my main target was a CoolMonster: +- Video card: CT69000 +- CPU: PENTIUM 266MHz + +and my host a Windows NT + Tornado 2. + + +Installation +------------ + +1. Mesa sources must be in root directory (C:\) + +2. Add the following line to your torVars.bat: +set MESA_BASE=C:\Mesa + +OR copy the new torVars.bat in your bin path: +c:/Mesa/src/ugl/tornado/torVars.sample -> +/mnt/nt/Tornado/host/x86-win32/bin/torVars (for example) + +3. In a command prompt: +$ torVars +$ cd c:\Mesa +$ make -f Makefile.ugl CPU=PENTIUM + +Take a long while... + +5. Include all the files from ugldemos folder to build some downloadable + application modules + +4. Download UGL/Mesa object files on target + +For example via the WindShell: +ld < c:\Tornado\target\lib\objMesaGL.o +ld < c:\Tornado\target\lib\objMesaUGL.o +ld < c:\Tornado\target\lib\objMesaGLU.o +ld < c:\Tornado\target\lib\objGLUTshapes.o +ld < c:\Tornado\target\lib\objMesaOS.o + +6. Download the application modules. + +7. In WindShell, run: +-> uglalldemos + +During the show some messages will appear, it provides some useful +information on key management. + + +Coding +------ + +Sample Usage: + +In addition to the usual ugl calls to initialize UGL, (may be find an +input driver), you must do the following to use the UGL/Mesa interface: + +1. Call uglMesaCreateContext() to create a UGL/Mesa rendering context, + given the display format. + +2. Call uglMesaMakeCurrent() to bind the UGL/Mesa buffers to an + UGL/Mesa Context and to make the context the current one. + +3. Make gl* calls to render your graphics. + +4. Use uglMesaSwapBuffers() when double buffering to swap front/back buffers. + +5. Before the UGL is destroyed, call MesaDestroyContext(). + +6. Before exiting, call if required uglEventQDestroy and then uglDeinitialize(); + +Limitations +----------- + +I found the following limitations in my driver : + - Color Indexed management is only in 8 bits + - The front and the back buffer must have the structure (mode and + size). A structure umc->buffer is requisite if the front and back + buffers are different. + - It isn't possible to mix UGL/OpenGL application with a software + double buffer (to fix) + +Modifications +------------ + +New files in Mesa: +- Makefile.ugl +- rules.windmlmesa +- docs/README.UGL +- include/GL/uglmesa.h +- si-glu/Makefile.ugl +- src/Makefile.ugl +- src/ugl/torGLUTShapesInit.c +- src/ugl/torMesaUGLInit.c +- src/ugl/ugl_api.c +- src/ugl/ugl_dd.c +- src/ugl/ugl_glutshapes.c +- src/ugl/ugl_line.c +- src/ugl/ugl_span.c +- src/ugl/ugl_tri.c +- src/ugl/uglmesaP.h +- ugldemos/* + +Modified files in Tornado 2.0: +- c:\Tornado\host\x86-win32\bin\torVars.bat +rem Command line build environments +set WIND_HOST_TYPE=x86-win32 +set WIND_BASE=C:\Tornado +set MESA_BASE=C:\Mesa +set PATH=%WIND_BASE%\host\%WIND_HOST_TYPE%\bin;%PATH% +- c:\Tornado\target\config\comps\VxWorks\01uglmesa.cdf +- c:\Tornado\target\h\GL\* + +Todo +---- +- GCC 2.96, ASM compilation + +Thanks to: +---------- + +Precision Insight team for their great job around Mesa, XFree, and DRI. +Wind River Systems to take me as an intern. + + +Stephane Raimbault + +July 24, 2001 diff --git a/include/GL/uglglutshapes.h b/include/GL/uglglutshapes.h new file mode 100644 index 00000000000..28192de2d52 --- /dev/null +++ b/include/GL/uglglutshapes.h @@ -0,0 +1,45 @@ +/* uglglutshapes.h - Public header GLUT Shapes */ + +/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */ + +/* This program is freely distributable without licensing fees and is + provided without guarantee or warrantee expressed or implied. This + program is -not- in the public domain. */ + +#ifndef GLUTSHAPES_H +#define GLUTSHAPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <GL/gl.h> + +void glutWireSphere (GLdouble radius, GLint slices, GLint stacks); +void glutSolidSphere (GLdouble radius, GLint slices, GLint stacks); +void glutWireCone (GLdouble base, GLdouble height, + GLint slices, GLint stacks); +void glutSolidCone (GLdouble base, GLdouble height, + GLint slices, GLint stacks); +void glutWireCube (GLdouble size); +void glutSolidCube (GLdouble size); +void glutWireTorus (GLdouble innerRadius, GLdouble outerRadius, + GLint sides, GLint rings); +void glutSolidTorus (GLdouble innerRadius, GLdouble outerRadius, + GLint sides, GLint rings); +void glutWireDodecahedron (void); +void glutSolidDodecahedron (void); +void glutWireOctahedron (void); +void glutSolidOctahedron (void); +void glutWireTetrahedron (void); +void glutSolidTetrahedron (void); +void glutWireIcosahedron (void); +void glutSolidIcosahedron (void); +void glutWireTeapot (GLdouble size); +void glutSolidTeapot (GLdouble size); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/GL/uglmesa.h b/include/GL/uglmesa.h new file mode 100644 index 00000000000..44f8fc035ee --- /dev/null +++ b/include/GL/uglmesa.h @@ -0,0 +1,322 @@ +/* uglmesa.h - Public header UGL/Mesa */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Author: + * Stephane Raimbault <[email protected]> + */ + +#ifndef UGLMESA_H +#define UGLMESA_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define UGL_MESA_MAJOR_VERSION 1 +#define UGL_MESA_MINOR_VERSION 0 + +#include <GL/gl.h> +#include <ugl/ugl.h> + +/* + * Values for display mode of uglMesaCreateContext () + */ + +#define UGL_MESA_SINGLE 0x00 +#define UGL_MESA_DOUBLE 0x01 +#define UGL_MESA_DOUBLE_SW 0x02 +#define UGL_MESA_DOUBLE_HW 0x03 + +#define UGL_MESA_FULLSCREEN_WIDTH 0x0 +#define UGL_MESA_FULLSCREEN_HEIGHT 0x0 + +/* + * Pixel format + */ +#define UGL_MESA_ARGB8888 0x01 +#define UGL_MESA_RGB565 0x02 +#define UGL_MESA_RGB888 0x03 +#define UGL_MESA_ARGB4444 0x04 +#define UGL_MESA_CI 0x05 +#define UGL_MESA_DITHER_RGB 0x10 + +/* + * uglMesaPixelStore() parameters: + */ + +#define UGL_MESA_ROW_LENGTH 0x10 +#define UGL_MESA_Y_UP 0x11 + +/* + * Accepted by uglMesaGetIntegerv: + */ + +#define UGL_MESA_LEFT_X 0x18 +#define UGL_MESA_TOP_Y 0x19 +#define UGL_MESA_WIDTH 0x20 +#define UGL_MESA_HEIGHT 0x21 +#define UGL_MESA_DISPLAY_WIDTH 0x22 +#define UGL_MESA_DISPLAY_HEIGHT 0x23 +#define UGL_MESA_COLOR_FORMAT 0x24 +#define UGL_MESA_COLOR_MODEL 0x25 +#define UGL_MESA_PIXEL_FORMAT 0x26 +#define UGL_MESA_TYPE 0x27 +#define UGL_MESA_RGB 0x28 +#define UGL_MESA_COLOR_INDEXED 0x29 + +/* + * typedefs + */ + +typedef struct uglMesaContext * UGL_MESA_CONTEXT; + +/* + * Create an Mesa/UGL rendering context. The attributes needed are + * double buffer flag and a context sharelist. + * + * It's necessary to first call this function before use uglMakeCurrentContext. + * This function provides neither stencil nor accumulation buffer only + * a depth buffer to reduce memory footprint. + * + * Input: db_mode - UGL_MESA_SINGLE = single buffer mode + * UGL_MESA_DOUBLE = double buffer mode (HW fallback -> SW) + * UGL_MESA_DOUBLE_SW = double buffer software + * UGL_MESA_DOUBLE_HW = double buffer hardware + * share_list - specifies another UGL_MESA_CONTEXT with which to share + * display lists. NULL indicates no sharing. + * + * Return: a UGL_MESA_CONTEXT, or zero if error + */ + +UGL_MESA_CONTEXT uglMesaCreateNewContext (GLenum db_mode, + UGL_MESA_CONTEXT share_list); + +/* + * Create an UGL/Mesa rendering context and specify desired + * size of depth buffer, stencil buffer and accumulation buffer. + * If you specify zero for depth_bits, stencil_bits, + * accum_[red|gren|blue]_bits, you can save some memory. + * + * INPUT: db_mode - double buffer mode + * depth_bits - depth buffer size + * stencil_bits - stencil buffer size + * accum_red_bits - accumulation red buffer size + * accum_green_bits - accumulation green buffer size + * accum_blue_bits -accumulation blue buffer size + * accum_alpha_bits -accumulation alpha buffer size + * share_list - specifies another UGL_MESA_CONTEXT with which to share + * display lists. NULL indicates no sharing. + */ +UGL_MESA_CONTEXT uglMesaCreateNewContextExt (GLenum db_flag, + GLint depth_bits, + GLint stencil_bits, + GLint accum_red_bits, + GLint accum_green_bits, + GLint accum_blue_bits, + GLint accum_alpha_bits, + UGL_MESA_CONTEXT share_list); + +/* + * Bind an UGL_MESA_CONTEXT to an image buffer. The image buffer is + * just a block of memory which the client provides. Its size must be + * at least as large as width*height*sizeof(type). Its address should + * be a multiple of 4 if using RGBA mode. + * + * Image data is stored in the order of glDrawPixels: row-major order + * with the lower-left image pixel stored in the first array position + * (ie. bottom-to-top). + * + * Since the only type initially supported is GL_UNSIGNED_BYTE, if the + * context is in RGBA mode, each pixel will be stored as a 4-byte RGBA + * value. If the context is in color indexed mode, each pixel will be + * stored as a 1-byte value. + * + * If the context's viewport hasn't been initialized yet, it will now be + * initialized to (0, 0, width, height). + * + * Input: umc - a rendering context + * left, top - coordinates in pixels of (left,top) pixel + * (0,0) in fullscreen mode. + * width, height - size of image buffer in pixels, at least 1 + * else fullscreen dimensions are used (UGL_MESA_DISPLAY_WIDTH + * and UGL_MESA_DISPLAY_HEIGHT). + * + * Return: GL_TRUE if success, GL_FALSE if error because of invalid umc, + * width<1, height<1, width>internal limit or height>internal limit. + */ + +GLboolean uglMesaMakeCurrentContext (UGL_MESA_CONTEXT umc, + GLsizei left, GLsizei top, + GLsizei width, GLsizei height); + +/* + * Move an OpenGL window by a delta value + * + * Input: dx, dy - delta values in pixels + * + * Return: GL_TRUE if success, GL_FALSE if error because of invalid + * coordinates. + */ +GLboolean uglMesaMoveWindow (GLsizei dx, GLsizei dy); + +/* + * Move an OpenGL window to an absolute position + * + * Input: left, top - new coordinates in pixels + * + * Return: GL_TRUE if success, GL_FALSE if error because of invalid + * coordinates. + */ +GLboolean uglMesaMoveToWindow (GLsizei left, GLsizei top); + +/* + * Resize an OpenGL window by a delta value + * + * Input: dw, dh - delta values in pixels + * + * Return: GL_TRUE if success, GL_FALSE if error because of invalid + * coordinates. + */ +GLboolean uglMesaResizeWindow (GLsizei dw, GLsizei dh); + +/* + * Resize an OpenGL window to an absolute size + * + * Input: width, height - new dimensions in pixels + * + * Return: GL_TRUE if success, GL_FALSE if error because of invalid + * coordinates. + */ +GLboolean uglMesaResizeToWindow (GLsizei width, GLsizei height); + +/* + * Destroy the current UGL/Mesa rendering context + * + */ +void uglMesaDestroyContext (void); + +/* + * Return the current UGL/Mesa context + * + * Return: a UGL/Mesa context, or NULL if error + * + */ +UGL_MESA_CONTEXT uglMesaGetCurrentContext (void); + +/* + * Swap front and back buffers in double buffering mode. This + * function is a no-op if there's no back buffer. In case of software + * double buffering a copy occurs from off-screen buffer to front + * buffer. Works faster with an hardware support. + */ + +void uglMesaSwapBuffers (void); + +/* + * Set pixel store/packing parameters for the current context. This + * is similar to glPixelStore. UGL uses Y coordinates increase + * downward. + * + * Input: pname - UGL_MESA_ROW_LENGTH + * zero, same as image width (default). + * value specify actual pixels per row in image buffer + * UGL_MESA_Y_UP: + * zero = Y coordinates increase downward (default) + * non-zero = Y coordinates increase upward + * value - value for the parameter pname + */ + +void uglMesaPixelStore (GLint pname, GLint value); + +/* + * Return an integer value like glGetIntegerv. + * + * Input: pname - UGL_MESA_LEFT_X return the x axis value + * of the most left pixel + * UGL_MESA_TOP_Y return the y axis value + * of the topper pixel + * UGL_MESA_WIDTH return current image width + * UGL_MESA_HEIGHT return current image height + * UGL_MESA_COLOR_FORMAT return image color format + * UGL_MESA_COLOR_MODEL return image color model + * UGL_MESA_PIXEL_FORMAT return pixel format + * UGL_MESA_ROW_LENGTH return row length in pixels + * UGL_MESA_RGB return true if RGB + * UGL_MESA_COLOR_INDEXED return true if color indexed + * value - pointer to integer in which to return result. + */ +void uglMesaGetIntegerv (GLint pname, GLint *value); + +/* + * Return the depth buffer associated with an UGL/Mesa context. + * + * Output: width, height - size of buffer in pixels + * bytesPerValue - bytes per depth value (2 or 4) + * buffer - pointer to depth buffer values + * Return: GL_TRUE or GL_FALSE to indicate success or failure. + * + */ +GLboolean uglMesaGetDepthBuffer (GLint *width, GLint *height, + GLint *bytesPerValue, void **buffer); + +/* + * Return the color buffer associated with an UGL/Mesa context. + * Input: c - the UGL/Mesa context + * Output: width, height - size of buffer in pixels + * format - buffer format (UGLMESA_FORMAT) + * buffer - pointer to color buffer values + * Return: GL_TRUE or GL_FALSE to indicate success or failure. + * + */ +GLboolean uglMesaGetColorBuffer (GLint *width, GLint *height, + GLint *format, void **buffer); + +/* + * Color allocation in indexed mode. + * This function does nothing in RGB mode. + * + * Input: index - Value for the current color index + * red - Red component (between 0 and 1) + * green - Green component (between 0 and 1) + * blue - Blue component (between 0 and 1) + * + * Return: GL_TRUE if success, or GL_FALSE if index<0 or * clutSize<index, + * red, green and blue are not between 0.0 and 1.0. + * + */ + +GLboolean uglMesaSetColor (GLubyte index, GLfloat red, + GLfloat green, GLfloat blue); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/progs/windml/Makefile.ugl b/progs/windml/Makefile.ugl new file mode 100644 index 00000000000..90b0b29bc82 --- /dev/null +++ b/progs/windml/Makefile.ugl @@ -0,0 +1,68 @@ +# Mesa 3-D graphics library +# Version: 3.5 +# +# Copyright (C) 2001 Wind River Systems, Inc + +# The MIT License +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# Makefile for UGL/Mesa demos + +DEMO_SOURCES = readtex.c uglaccum.c uglalldemos.c uglbounce.c uglcube.c \ +ugldrawpix.c uglflip.c uglgears.c uglicotorus.c uglline.c uglolympic.c \ +uglpoint.c uglstencil.c uglteapot.c ugltexcube.c ugltexcyl.c +#win2d3d/winRoot.c win2d3d/winBall.c win2d3d/winPuzzle.c win2d3d/winHello.c \ +#win2d3d/winImage.c win2d3d/winGears.c + +DEMO_OBJECTS = $(DEMO_SOURCES:.c=.o) + +SOURCES = $(DEMO_SOURCES) + +include ../rules.windml + +##### TARGETS ##### + +all: depend.$(CPU)$(TOOL) $(DEMO_OBJECTS) + +depend.$(CPU)$(TOOL): +ifeq ($(WIND_HOST_TYPE),x86-win32) + @ $(RM) $@ + @ $(ECHO) Creating depend.$(CPU)$(TOOL) +ifneq ($(SOURCES),) + @ for %f in ($(SOURCES)) do \ + $(CC) -MM $(CFLAGS) %f >>$@ +endif +else +Makefile + @ $(RM) $@ + @ $(ECHO) "Creating depend.$(CPU)$(TOOL)" +ifneq ($(SOURCES),) + @ for FILE in $(filter-out $(NODEPENDOBJS), $(SOURCES)); \ + do \ + $(CC) -MM $(CFLAGS) $$FILE \ + | $(TCL) $(BIN_DIR)/depend.tcl $(TGT_DIR) >>$@; \ + done +endif +endif + +.PHONY = clean + +clean: + $(RM) $(DEMO_OBJECTS) + $(RM) depend.$(CPU)$(TOOL) diff --git a/progs/windml/readtex.c b/progs/windml/readtex.c new file mode 100644 index 00000000000..659c49de8de --- /dev/null +++ b/progs/windml/readtex.c @@ -0,0 +1,365 @@ +/* readtex.c */ + +/* + * Read an SGI .rgb image file and generate a mipmap texture set. + * Much of this code was borrowed from SGI's tk OpenGL toolkit. + */ + +#include <GL/gl.h> +#include <GL/glu.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "../util/readtex.h" + + +#ifndef SEEK_SET +# define SEEK_SET 0 +#endif + + +/* +** RGB Image Structure +*/ + +typedef struct _TK_RGBImageRec { + GLint sizeX, sizeY; + GLint components; + unsigned char *data; +} TK_RGBImageRec; + + + +/******************************************************************************/ + +typedef struct _rawImageRec { + unsigned short imagic; + unsigned short type; + unsigned short dim; + unsigned short sizeX, sizeY, sizeZ; + unsigned long min, max; + unsigned long wasteBytes; + char name[80]; + unsigned long colorMap; + FILE *file; + unsigned char *tmp, *tmpR, *tmpG, *tmpB, *tmpA; + unsigned long rleEnd; + GLuint *rowStart; + GLint *rowSize; +} rawImageRec; + +/******************************************************************************/ + +static void ConvertShort(unsigned short *array, long length) +{ + unsigned long b1, b2; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + *array++ = (unsigned short) ((b1 << 8) | (b2)); + } +} + +static void ConvertLong(GLuint *array, long length) +{ + unsigned long b1, b2, b3, b4; + unsigned char *ptr; + + ptr = (unsigned char *)array; + while (length--) { + b1 = *ptr++; + b2 = *ptr++; + b3 = *ptr++; + b4 = *ptr++; + *array++ = (b1 << 24) | (b2 << 16) | (b3 << 8) | (b4); + } +} + +static rawImageRec *RawImageOpen(const char *fileName) +{ + union { + int testWord; + char testByte[4]; + } endianTest; + rawImageRec *raw; + GLenum swapFlag; + int x; + + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { + swapFlag = GL_TRUE; + } else { + swapFlag = GL_FALSE; + } + + raw = (rawImageRec *)malloc(sizeof(rawImageRec)); + if (raw == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + if ((raw->file = fopen(fileName, "rb")) == NULL) { + perror(fileName); + return NULL; + } + + fread(raw, 1, 12, raw->file); + + if (swapFlag) { + ConvertShort(&raw->imagic, 6); + } + + raw->tmp = (unsigned char *)malloc(raw->sizeX*256); + raw->tmpR = (unsigned char *)malloc(raw->sizeX*256); + raw->tmpG = (unsigned char *)malloc(raw->sizeX*256); + raw->tmpB = (unsigned char *)malloc(raw->sizeX*256); + if (raw->sizeZ==4) { + raw->tmpA = (unsigned char *)malloc(raw->sizeX*256); + } + if (raw->tmp == NULL || raw->tmpR == NULL || raw->tmpG == NULL || + raw->tmpB == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + + if ((raw->type & 0xFF00) == 0x0100) { + x = raw->sizeY * raw->sizeZ * sizeof(GLuint); + raw->rowStart = (GLuint *)malloc(x); + raw->rowSize = (GLint *)malloc(x); + if (raw->rowStart == NULL || raw->rowSize == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + raw->rleEnd = 512 + (2 * x); + fseek(raw->file, 512, SEEK_SET); + fread(raw->rowStart, 1, x, raw->file); + fread(raw->rowSize, 1, x, raw->file); + if (swapFlag) { + ConvertLong(raw->rowStart, (long) (x/sizeof(GLuint))); + ConvertLong((GLuint *)raw->rowSize, (long) (x/sizeof(GLint))); + } + } + return raw; +} + +static void RawImageClose(rawImageRec *raw) +{ + + fclose(raw->file); + free(raw->tmp); + free(raw->tmpR); + free(raw->tmpG); + free(raw->tmpB); + if (raw->sizeZ>3) { + free(raw->tmpA); + } + free(raw); +} + +static void RawImageGetRow(rawImageRec *raw, unsigned char *buf, int y, int z) +{ + unsigned char *iPtr, *oPtr, pixel; + int count, done = 0; + + if ((raw->type & 0xFF00) == 0x0100) { + fseek(raw->file, (long) raw->rowStart[y+z*raw->sizeY], SEEK_SET); + fread(raw->tmp, 1, (unsigned int)raw->rowSize[y+z*raw->sizeY], + raw->file); + + iPtr = raw->tmp; + oPtr = buf; + while (!done) { + pixel = *iPtr++; + count = (int)(pixel & 0x7F); + if (!count) { + done = 1; + return; + } + if (pixel & 0x80) { + while (count--) { + *oPtr++ = *iPtr++; + } + } else { + pixel = *iPtr++; + while (count--) { + *oPtr++ = pixel; + } + } + } + } else { + fseek(raw->file, 512+(y*raw->sizeX)+(z*raw->sizeX*raw->sizeY), + SEEK_SET); + fread(buf, 1, raw->sizeX, raw->file); + } +} + + +static void RawImageGetData(rawImageRec *raw, TK_RGBImageRec *final) +{ + unsigned char *ptr; + int i, j; + + final->data = (unsigned char *)malloc((raw->sizeX+1)*(raw->sizeY+1)*4); + if (final->data == NULL) { + fprintf(stderr, "Out of memory!\n"); + } + + ptr = final->data; + for (i = 0; i < (int)(raw->sizeY); i++) { + RawImageGetRow(raw, raw->tmpR, i, 0); + RawImageGetRow(raw, raw->tmpG, i, 1); + RawImageGetRow(raw, raw->tmpB, i, 2); + if (raw->sizeZ>3) { + RawImageGetRow(raw, raw->tmpA, i, 3); + } + for (j = 0; j < (int)(raw->sizeX); j++) { + *ptr++ = *(raw->tmpR + j); + *ptr++ = *(raw->tmpG + j); + *ptr++ = *(raw->tmpB + j); + if (raw->sizeZ>3) { + *ptr++ = *(raw->tmpA + j); + } + } + } +} + + +static TK_RGBImageRec *tkRGBImageLoad(const char *fileName) +{ + rawImageRec *raw; + TK_RGBImageRec *final; + + raw = RawImageOpen(fileName); + if (!raw) { + fprintf(stderr, "File not found\n"); + return NULL; + } + final = (TK_RGBImageRec *)malloc(sizeof(TK_RGBImageRec)); + if (final == NULL) { + fprintf(stderr, "Out of memory!\n"); + return NULL; + } + final->sizeX = raw->sizeX; + final->sizeY = raw->sizeY; + final->components = raw->sizeZ; + RawImageGetData(raw, final); + RawImageClose(raw); + return final; +} + + +static void FreeImage( TK_RGBImageRec *image ) +{ + free(image->data); + free(image); +} + + +/* + * Load an SGI .rgb file and generate a set of 2-D mipmaps from it. + * Input: imageFile - name of .rgb to read + * intFormat - internal texture format to use, or number of components + * Return: GL_TRUE if success, GL_FALSE if error. + */ +GLboolean LoadRGBMipmaps( const char *imageFile, GLint intFormat ) +{ + GLint w, h; + return LoadRGBMipmaps2( imageFile, GL_TEXTURE_2D, intFormat, &w, &h ); +} + + + +GLboolean LoadRGBMipmaps2( const char *imageFile, GLenum target, + GLint intFormat, GLint *width, GLint *height ) +{ + GLint error; + GLenum format; + TK_RGBImageRec *image; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return GL_FALSE; + } + + if (image->components==3) { + format = GL_RGB; + } + else if (image->components==4) { + format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBMipmaps %d-component images not implemented\n", + image->components ); + return GL_FALSE; + } + + error = gluBuild2DMipmaps( target, + intFormat, + image->sizeX, image->sizeY, + format, + GL_UNSIGNED_BYTE, + image->data ); + + *width = image->sizeX; + *height = image->sizeY; + + FreeImage(image); + + return error ? GL_FALSE : GL_TRUE; +} + + + +/* + * Load an SGI .rgb file and return a pointer to the image data. + * Input: imageFile - name of .rgb to read + * Output: width - width of image + * height - height of image + * format - format of image (GL_RGB or GL_RGBA) + * Return: pointer to image data or NULL if error + */ +GLubyte *LoadRGBImage( const char *imageFile, GLint *width, GLint *height, + GLenum *format ) +{ + TK_RGBImageRec *image; + GLint bytes; + GLubyte *buffer; + + image = tkRGBImageLoad( imageFile ); + if (!image) { + return NULL; + } + + if (image->components==3) { + *format = GL_RGB; + } + else if (image->components==4) { + *format = GL_RGBA; + } + else { + /* not implemented */ + fprintf(stderr, + "Error in LoadRGBImage %d-component images not implemented\n", + image->components ); + return NULL; + } + + *width = image->sizeX; + *height = image->sizeY; + + bytes = image->sizeX * image->sizeY * image->components; + buffer = (GLubyte *) malloc(bytes); + if (!buffer) + return NULL; + + memcpy( (void *) buffer, (void *) image->data, bytes ); + + FreeImage(image); + + return buffer; +} + diff --git a/progs/windml/uglaccum.c b/progs/windml/uglaccum.c new file mode 100644 index 00000000000..4748618d624 --- /dev/null +++ b/progs/windml/uglaccum.c @@ -0,0 +1,240 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ + +/* Original name: accanti.c + * + * Conversion to UGL/Mesa by Stephane Raimbault + */ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/uglglutshapes.h> + +#include "../book/jitter.h" + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +/* Initialize lighting and other values. + */ +UGL_LOCAL void initGL(GLsizei w, GLsizei h) + { + GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 }; + GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; + + glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); + glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 50.0); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel (GL_FLAT); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearAccum(0.0, 0.0, 0.0, 0.0); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho (-2.25, 2.25, -2.25*h/w, 2.25*h/w, -10.0, 10.0); + else + glOrtho (-2.25*w/h, 2.25*w/h, -2.25, 2.25, -10.0, 10.0); + glMatrixMode(GL_MODELVIEW); + } + +UGL_LOCAL void displayObjects(void) + { + GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; + GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 }; + GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 }; + GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 }; + + glPushMatrix (); + glRotatef (30.0, 1.0, 0.0, 0.0); + + glPushMatrix (); + glTranslatef (-0.80, 0.35, 0.0); + glRotatef (100.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse); + glutSolidTorus (0.275, 0.85, 16, 16); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-0.75, -0.50, 0.0); + glRotatef (45.0, 0.0, 0.0, 1.0); + glRotatef (45.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse); + glutSolidCube (1.5); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.75, 0.60, 0.0); + glRotatef (30.0, 1.0, 0.0, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse); + glutSolidSphere (1.0, 16, 16); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (0.70, -0.90, 0.25); + glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse); + glutSolidOctahedron (); + glPopMatrix (); + + glPopMatrix (); + } + +#define ACSIZE 8 + +UGL_LOCAL void drawGL(void) + { + GLint viewport[4]; + int jitter; + + glGetIntegerv (GL_VIEWPORT, viewport); + + glClear(GL_ACCUM_BUFFER_BIT); + for (jitter = 0; jitter < ACSIZE; jitter++) + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glPushMatrix (); +/* Note that 4.5 is the distance in world space between + * left and right and bottom and top. + * This formula converts fractional pixel movement to + * world coordinates. + */ + glTranslatef (j8[jitter].x*4.5/viewport[2], + j8[jitter].y*4.5/viewport[3], 0.0); + displayObjects (); + glPopMatrix (); + glAccum(GL_ACCUM, 1.0/ACSIZE); + } + glAccum (GL_RETURN, 1.0); + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLAccum (void); + +void uglaccum (void) + { + taskSpawn("tAccum", 210, VX_FP_TASK, 100000, + (FUNCPTR)windMLAccum, 0,1,2,3,4,5,6,7,8,9); + } + +void windMLAccum(void) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei width, height; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + umc = uglMesaCreateNewContextExt(GL_TRUE, + 16, + 0, + 8,8,8,0, + NULL); + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, + UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + while (!getEvent()) + drawGL(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglalldemos.c b/progs/windml/uglalldemos.c new file mode 100644 index 00000000000..ebb2f27378a --- /dev/null +++ b/progs/windml/uglalldemos.c @@ -0,0 +1,98 @@ + +/* uglalldemos.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* +modification history +-------------------- +01a,17jul01,sra written +*/ + +/* +DESCRIPTION +Show all the UGL/Mesa demos +*/ + +#include <vxWorks.h> +#include <taskLib.h> + +void windMLPoint (void); +void windMLLine (void); +void windMLFlip (void); +void windMLCube (void); +void windMLBounce (void); +void windMLGears (void); +void windMLIcoTorus (void); +void windMLOlympic (void); +void windMLTexCube (void); +void windMLTexCyl (void); +void windMLTeapot (void); +void windMLStencil (void); +void windMLDrawPix (void); +void windMLAccum (void); +void windMLAllDemos (void); + +void uglalldemos (void) + { + taskSpawn("tAllDemos", 210, VX_FP_TASK, 200000, + (FUNCPTR)windMLAllDemos, 0,1,2,3,4,5,6,7,8,9); + } + +void windMLAllDemos(void) + { + + windMLPoint(); + + windMLLine(); + + windMLFlip(); + + windMLCube(); + + windMLBounce(); + + windMLGears(); + + windMLIcoTorus(); + + windMLOlympic(); + + windMLTexCube(); + + windMLTexCyl(); + + windMLTeapot(); + + windMLStencil(); + + windMLDrawPix(); + + windMLAccum(); + + return; + } diff --git a/progs/windml/uglbounce.c b/progs/windml/uglbounce.c new file mode 100644 index 00000000000..bcabf449632 --- /dev/null +++ b/progs/windml/uglbounce.c @@ -0,0 +1,268 @@ +/* + * Bouncing ball demo. + * + * This program is in the public domain + * + * Brian Paul + * + * Conversion to GLUT by Mark J. Kilgard + * + * Conversion to UGL/Mesa by Stephane Raimbault + */ + +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> + +#define COS(X) cos( (X) * 3.14159/180.0 ) +#define SIN(X) sin( (X) * 3.14159/180.0 ) + +#define RED 1 +#define WHITE 2 +#define CYAN 3 + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLuint Ball; +UGL_LOCAL GLfloat Zrot, Zstep; +UGL_LOCAL GLfloat Xpos, Ypos; +UGL_LOCAL GLfloat Xvel, Yvel; +UGL_LOCAL GLfloat Xmin, Xmax; +UGL_LOCAL GLfloat Ymin; +/* UGL_LOCAL GLfloat Ymax = 4.0; */ +UGL_LOCAL GLfloat G; + +UGL_LOCAL GLuint make_ball(void) + { + GLuint list; + GLfloat a, b; + GLfloat da = 18.0, db = 18.0; + GLfloat radius = 1.0; + GLuint color; + GLfloat x, y, z; + + list = glGenLists(1); + + glNewList(list, GL_COMPILE); + + color = 0; + for (a = -90.0; a + da <= 90.0; a += da) + { + glBegin(GL_QUAD_STRIP); + for (b = 0.0; b <= 360.0; b += db) + { + if (color) + { + glIndexi(RED); + glColor3f(1, 0, 0); + } + else + { + glIndexi(WHITE); + glColor3f(1, 1, 1); + } + + x = radius * COS(b) * COS(a); + y = radius * SIN(b) * COS(a); + z = radius * SIN(a); + glVertex3f(x, y, z); + + x = radius * COS(b) * COS(a + da); + y = radius * SIN(b) * COS(a + da); + z = radius * SIN(a + da); + glVertex3f(x, y, z); + + color = 1 - color; + } + glEnd(); + + } + + glEndList(); + + return list; + } + +UGL_LOCAL void initGL(GLsizei width, GLsizei height) + { + float aspect = (float) width / (float) height; + glViewport(0, 0, (GLint) width, (GLint) height); + + uglMesaSetColor(RED, 1.0, 0.0, 0.0); + uglMesaSetColor(WHITE, 1.0, 1.0, 1.0); + uglMesaSetColor(CYAN, 0.0, 1.0, 1.0); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-6.0 * aspect, 6.0 * aspect, -6.0, 6.0, -6.0, 6.0); + glMatrixMode(GL_MODELVIEW); + + } + +UGL_LOCAL void drawGL(void) + { + GLint i; + static float vel0 = -100.0; + + glClear(GL_COLOR_BUFFER_BIT); + + glIndexi(CYAN); + glColor3f(0, 1, 1); + glBegin(GL_LINES); + for (i = -5; i <= 5; i++) + { + glVertex2i(i, -5); + glVertex2i(i, 5); + } + for (i = -5; i <= 5; i++) + { + glVertex2i(-5, i); + glVertex2i(5, i); + } + for (i = -5; i <= 5; i++) + { + glVertex2i(i, -5); + glVertex2f(i * 1.15, -5.9); + } + glVertex2f(-5.3, -5.35); + glVertex2f(5.3, -5.35); + glVertex2f(-5.75, -5.9); + glVertex2f(5.75, -5.9); + glEnd(); + + glPushMatrix(); + glTranslatef(Xpos, Ypos, 0.0); + glScalef(2.0, 2.0, 2.0); + glRotatef(8.0, 0.0, 0.0, 1.0); + glRotatef(90.0, 1.0, 0.0, 0.0); + glRotatef(Zrot, 0.0, 0.0, 1.0); + + glCallList(Ball); + + glPopMatrix(); + + glFlush(); + + uglMesaSwapBuffers(); + + Zrot += Zstep; + + Xpos += Xvel; + if (Xpos >= Xmax) + { + Xpos = Xmax; + Xvel = -Xvel; + Zstep = -Zstep; + } + if (Xpos <= Xmin) + { + Xpos = Xmin; + Xvel = -Xvel; + Zstep = -Zstep; + } + Ypos += Yvel; + Yvel += G; + if (Ypos < Ymin) + { + Ypos = Ymin; + if (vel0 == -100.0) + vel0 = fabs(Yvel); + Yvel = vel0; + } + } + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLBounce (void); + +void uglbounce (void) + { + taskSpawn("tBounce", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLBounce, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLBounce(void) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + Zrot = 0.0; + Zstep = 6.0; + Xpos = 0.0; + Ypos = 1.0; + Xvel = 0.2; + Yvel = 0.0; + Xmin = -4.0; + Xmax = 4.0; + Ymin = -3.8; + G = -0.1; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + Ball = make_ball(); + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + glDisable(GL_DITHER); + glShadeModel(GL_FLAT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + while(!getEvent()) + drawGL(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + + return; + } diff --git a/progs/windml/uglcube.c b/progs/windml/uglcube.c new file mode 100644 index 00000000000..9080ba1fb98 --- /dev/null +++ b/progs/windml/uglcube.c @@ -0,0 +1,253 @@ +/* uglcube.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* +DESCRIPTION +Draw a smooth cube. +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL GLfloat rotx; +UGL_LOCAL GLfloat roty; +UGL_LOCAL GLuint theCube; + +UGL_LOCAL void cube() + { + + /* Front */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glEnd(); + + + /* Back */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glEnd(); + + + /* Right */ + glBegin(GL_QUADS); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glEnd(); + + /* Left */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glEnd(); + + /* Top */ + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glEnd(); + + + /* Bottom */ + glBegin(GL_QUADS); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glEnd(); + } + +UGL_LOCAL void initGL + ( + int Width, + int Height + ) + { + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + glShadeModel(GL_SMOOTH); + + theCube = glGenLists(1); + glNewList(theCube, GL_COMPILE); + cube(); + glEndList(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0f, (GLfloat) Width / (GLfloat) Height, 0.1f, 100.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -6.0f); + } + + +/* The main drawing function. */ + +UGL_LOCAL void drawGL() + { + + /* Clear The Screen And The Depth Buffer */ + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* Rotate the cube */ + + glRotatef(rotx, 1.0f, 0.0f, 0.0f); + glRotatef(roty, 0.0f, 1.0f, 0.0f); + + glCallList(theCube); + + glFlush(); + + uglMesaSwapBuffers(); + } + + +/* The function called whenever a key is pressed. */ + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLCube (void); + +void uglcube (void) + { + taskSpawn("tCube", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLCube, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLCube (void) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + rotx = 2.5f; + roty = 1.0f; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + /* Initialize our window. */ + + initGL(width, height); + + while (!getEvent()) + drawGL(); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/ugldrawpix.c b/progs/windml/ugldrawpix.c new file mode 100644 index 00000000000..678f423d2e3 --- /dev/null +++ b/progs/windml/ugldrawpix.c @@ -0,0 +1,429 @@ +/* + * glDrawPixels demo/test/benchmark + * + * Brian Paul September 25, 1997 This file is in the public domain. + * + * Conversion to UGL/Mesa by Stephane Raimbault july, 2001 + */ + +/* + * $Log: ugldrawpix.c,v $ + * Revision 1.1 2001/08/20 16:07:11 brianp + * WindML driver (Stephane Raimbault) + * + * Revision 1.5 2000/12/24 22:53:54 pesco + * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util. + * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus: + * Essentially the same. + * Program files updated to include "readtex.c", not "../util/readtex.c". + * * demos/reflect.c: Likewise for "showbuffer.c". + * + * + * * Makefile.am (EXTRA_DIST): Added top-level regular files. + * + * * include/GL/Makefile.am (INC_X11): Added glxext.h. + * + * + * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include + * Mesa GGI headers in dist even if HAVE_GGI is not given. + * + * * configure.in: Look for GLUT and demo source dirs in $srcdir. + * + * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch]. + * More source list updates in various Makefile.am's. + * + * * Makefile.am (dist-hook): Remove CVS directory from distribution. + * (DIST_SUBDIRS): List all possible subdirs here. + * (SUBDIRS): Only list subdirs selected for build again. + * The above two applied to all subdir Makefile.am's also. + * + * Revision 1.4 2000/09/08 21:45:21 brianp + * added dither key option + * + * Revision 1.3 1999/10/28 18:23:29 brianp + * minor changes to Usage() function + * + * Revision 1.2 1999/10/21 22:13:58 brianp + * added f key to toggle front/back drawing + * + * Revision 1.1.1.1 1999/08/19 00:55:40 jtg + * Imported sources + * + * Revision 3.3 1999/03/28 18:18:33 brianp + * minor clean-up + * + * Revision 3.2 1998/11/05 04:34:04 brianp + * moved image files to ../images/ directory + * + * Revision 3.1 1998/02/22 16:43:17 brianp + * added a few casts to silence compiler warnings + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <tickLib.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#include "../util/readtex.h" + +#define IMAGE_FILE "Mesa/images/girl.rgb" + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL int ImgWidth, ImgHeight; +UGL_LOCAL GLenum ImgFormat; +UGL_LOCAL GLubyte *Image; + +UGL_LOCAL int Xpos, Ypos; +UGL_LOCAL int SkipPixels, SkipRows; +UGL_LOCAL int DrawWidth, DrawHeight; +UGL_LOCAL float Xzoom, Yzoom; +UGL_LOCAL GLboolean Scissor; +UGL_LOCAL GLboolean DrawFront; +UGL_LOCAL GLboolean Dither; + +UGL_LOCAL void cleanUp (void); + +UGL_LOCAL void reset(void) + { + Xpos = Ypos = 20; + DrawWidth = ImgWidth; + DrawHeight = ImgHeight; + SkipPixels = SkipRows = 0; + Scissor = GL_FALSE; + Xzoom = Yzoom = 1.0; + } + +UGL_LOCAL void initGL(GLboolean ciMode, GLsizei width, GLsizei height) + { + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + + Image = LoadRGBImage(IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat); + if (!Image) + { + printf("Couldn't read %s\n", IMAGE_FILE); + cleanUp(); + exit(1); + } + + glScissor(width/4, height/4, width/2, height/2); + + if (ciMode) + { + /* Convert RGB image to grayscale */ + GLubyte *indexImage = malloc( ImgWidth * ImgHeight ); + GLint i; + for (i=0; i<ImgWidth*ImgHeight; i++) + { + int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; + indexImage[i] = gray / 3; + } + free(Image); + Image = indexImage; + ImgFormat = GL_COLOR_INDEX; + + for (i=0;i<255;i++) + { + float g = i / 255.0; + uglMesaSetColor(i, g, g, g); + } + } + + printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); + + reset(); + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + } + +UGL_LOCAL void drawGL(void) + { + glClear(GL_COLOR_BUFFER_BIT); + + /* This allows negative raster positions: */ + glRasterPos2i(0, 0); + glBitmap(0, 0, 0, 0, Xpos, Ypos, NULL); + + glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels); + glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows); + + glPixelZoom( Xzoom, Yzoom ); + + if (Scissor) + glEnable(GL_SCISSOR_TEST); + + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + + glDisable(GL_SCISSOR_TEST); + + uglMesaSwapBuffers(); + } + + +UGL_LOCAL void benchmark( void ) + { + int startTick, endTick, ticksBySec; + int draws; + double seconds, pixelsPerSecond; + + printf("Benchmarking (4 sec)...\n"); + + /* GL set-up */ + glPixelStorei(GL_UNPACK_SKIP_PIXELS, SkipPixels); + glPixelStorei(GL_UNPACK_SKIP_ROWS, SkipRows); + glPixelZoom( Xzoom, Yzoom ); + if (Scissor) + glEnable(GL_SCISSOR_TEST); + + if (DrawFront) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + + /* Run timing test */ + draws = 0; + + ticksBySec = sysClkRateGet (); + startTick = tickGet(); + + do { + glDrawPixels(DrawWidth, DrawHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + draws++; + endTick = tickGet (); + } while ((endTick - startTick)/ticksBySec < 4); /* 4 seconds */ + + /* GL clean-up */ + glDisable(GL_SCISSOR_TEST); + + /* Results */ + seconds = (endTick - startTick)/ticksBySec; + pixelsPerSecond = draws * DrawWidth * DrawHeight / seconds; + printf("Result: %d draws in %f seconds = %f pixels/sec\n", + draws, seconds, pixelsPerSecond); + } + +UGL_LOCAL void echoUse(void) + { + printf("Keys:\n"); + printf(" SPACE Reset Parameters\n"); + printf(" Up/Down Move image up/down\n"); + printf(" Left/Right Move image left/right\n"); + printf(" x Decrease X-axis PixelZoom\n"); + printf(" X Increase X-axis PixelZoom\n"); + printf(" y Decrease Y-axis PixelZoom\n"); + printf(" Y Increase Y-axis PixelZoom\n"); + printf(" w Decrease glDrawPixels width*\n"); + printf(" W Increase glDrawPixels width*\n"); + printf(" h Decrease glDrawPixels height*\n"); + printf(" H Increase glDrawPixels height*\n"); + printf(" p Decrease GL_UNPACK_SKIP_PIXELS*\n"); + printf(" P Increase GL_UNPACK_SKIP_PIXELS*\n"); + printf(" r Decrease GL_UNPACK_SKIP_ROWS*\n"); + printf(" R Increase GL_UNPACK_SKIP_ROWS*\n"); + printf(" s Toggle GL_SCISSOR_TEST\n"); + printf(" f Toggle front/back buffer drawing\n"); + printf(" d Toggle dithering\n"); + printf(" b Benchmark test\n"); + printf(" ESC Exit\n"); + printf("* Warning: no limits are imposed on these parameters so it's\n"); + printf(" possible to cause a segfault if you go too far.\n"); + } + + +UGL_LOCAL void readKey(UGL_WCHAR key) + { + switch (key) + { + case UGL_UNI_SPACE: + reset(); + break; + case 'd': + Dither = !Dither; + if (Dither) + glEnable(GL_DITHER); + else + glDisable(GL_DITHER); + break; + case 'w': + if (DrawWidth > 0) + DrawWidth--; + break; + case 'W': + DrawWidth++; + break; + case 'h': + if (DrawHeight > 0) + DrawHeight--; + break; + case 'H': + DrawHeight++; + break; + case 'p': + if (SkipPixels > 0) + SkipPixels--; + break; + case 'P': + SkipPixels++; + break; + case 'r': + if (SkipRows > 0) + SkipRows--; + break; + case 'R': + SkipRows++; + break; + case 's': + Scissor = !Scissor; + break; + case 'x': + Xzoom -= 0.1; + break; + case 'X': + Xzoom += 0.1; + break; + case 'y': + Yzoom -= 0.1; + break; + case 'Y': + Yzoom += 0.1; + break; + case 'b': + benchmark(); + break; + case 'f': + DrawFront = !DrawFront; + if (DrawFront) + glDrawBuffer(GL_FRONT); + else + glDrawBuffer(GL_BACK); + printf("glDrawBuffer(%s)\n", DrawFront ? "GL_FRONT" : "GL_BACK"); + break; + case UGL_UNI_UP_ARROW: + Ypos += 1; + break; + case UGL_UNI_DOWN_ARROW: + Ypos -= 1; + break; + case UGL_UNI_LEFT_ARROW: + Xpos -= 1; + break; + case UGL_UNI_RIGHT_ARROW: + Xpos += 1; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +UGL_LOCAL void cleanUp (void) + { + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + } + +void windMLDrawPix (void); + +void ugldrawpix (void) + { + taskSpawn ("tDrawPix", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLDrawPix, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLDrawPix (void) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLuint ciMode; + GLsizei width, height; + + Image = NULL; + Scissor = GL_FALSE; + DrawFront = GL_FALSE; + Dither = GL_TRUE; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + umc = uglMesaCreateNewContext (UGL_MESA_DOUBLE, NULL); + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_COLOR_INDEXED, &ciMode); + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(ciMode, width, height); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + cleanUp(); + + return; + } diff --git a/progs/windml/uglflip.c b/progs/windml/uglflip.c new file mode 100644 index 00000000000..ffc6ece2db1 --- /dev/null +++ b/progs/windml/uglflip.c @@ -0,0 +1,219 @@ + +/* uglflip.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Stephane Raimbault <[email protected]> + */ + +/* +DESCRIPTION +Draw a triangle and flip the screen +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#define BLACK (0) +#define RED (1) +#define GREEN (2) +#define BLUE (3) +#define CI_OFFSET 4 + +UGL_LOCAL GLuint rgb; +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL void initGL (void) + { + uglMesaSetColor(BLACK, 0.0, 0.0, 0.0); + uglMesaSetColor(RED, 1.0, 0.3, 0.3); + uglMesaSetColor(GREEN, 0.3, 1.0, 0.3); + uglMesaSetColor(BLUE, 0.3, 0.3, 1.0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(BLACK); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + } + +UGL_LOCAL void drawGL (void) + { + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_TRIANGLES); + (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED); + glVertex2f(0.75, -0.50); + (rgb) ? glColor3f(0.3, 1.0, 0.3) : glIndexi(GREEN); + glVertex2f(0.0, 0.75); + (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE); + glVertex2f(-0.75, -0.50); + glEnd(); + + glBegin(GL_LINES); + (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED); + glVertex2f(-1.0, 1.0); + (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE); + glVertex2f(1.0, -1.0); + glEnd(); + + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL void echoUse(void) + { + printf("tFlip keys:\n"); + printf(" d Toggle dithering\n"); + printf(" up Reduce the window\n"); + printf(" down Enlarge the window\n"); + printf(" page up Y==0 is the bottom line and increases upward\n"); + printf(" page down Y==0 is the bottom line and increases downward\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + + switch(key) + { + case UGL_UNI_UP_ARROW: + uglMesaResizeWindow(8, 8); + break; + case UGL_UNI_DOWN_ARROW: + glDrawBuffer(GL_FRONT_LEFT); + glClear(GL_COLOR_BUFFER_BIT); + glDrawBuffer(GL_BACK_LEFT); + uglMesaResizeWindow(-8, -8); + break; + case UGL_UNI_PAGE_UP: + uglMesaPixelStore(UGL_MESA_Y_UP, GL_TRUE); + break; + case UGL_UNI_PAGE_DOWN: + uglMesaPixelStore(UGL_MESA_Y_UP, GL_FALSE); + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + case 'd': + if (glIsEnabled(GL_DITHER)) + glDisable(GL_DITHER); + else + glEnable(GL_DITHER); + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + drawGL(); + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + { + readKey(pInputEvent->type.keyboard.key); + drawGL(); + } + } + + if (stopWex) + break; + } + } + +void windMLFlip (void); + +void uglflip (void) + { + taskSpawn("tFlip", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLFlip, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLFlip(void) + { + + UGL_INPUT_DEVICE_ID keyboardDevId; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE_SW, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + echoUse(); + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglgears.c b/progs/windml/uglgears.c new file mode 100644 index 00000000000..fe750a57d8d --- /dev/null +++ b/progs/windml/uglgears.c @@ -0,0 +1,422 @@ + +/* uglgears.c - WindML/Mesa example program */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + * + * Conversion to GLUT by Mark J. Kilgard + * Conversion to UGL/Mesa from GLUT by Stephane Raimbault + */ + +/* +DESCRIPTION +Spinning gears demo +*/ + +#include <stdio.h> +#include <math.h> +#include <tickLib.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define COUNT_FRAMES + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLfloat view_rotx, view_roty, view_rotz; +UGL_LOCAL GLint gear1, gear2, gear3; +UGL_LOCAL GLfloat angle; + +UGL_LOCAL GLuint limit; +UGL_LOCAL GLuint count; +UGL_LOCAL GLuint tickStart, tickStop, tickBySec; + + +/* +* Draw a gear wheel. You'll probably want to call this function when +* building a display list since we do a lot of trig here. +* +* Input: inner_radius - radius of hole at center +* outer_radius - radius at center of teeth +* width - width of gear +* teeth - number of teeth +* tooth_depth - depth of tooth +*/ + +UGL_LOCAL void gear + ( + GLfloat inner_radius, + GLfloat outer_radius, + GLfloat width, + GLint teeth, + GLfloat tooth_depth + ) + { + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth/2.0; + r2 = outer_radius + tooth_depth/2.0; + + da = 2.0*M_PI / teeth / 4.0; + + glShadeModel (GL_FLAT); + + glNormal3f (0.0, 0.0, 1.0); + + /* draw front face */ + glBegin (GL_QUAD_STRIP); + for (i=0;i<=teeth;i++) + { + angle = i * 2.0*M_PI / teeth; + glVertex3f (r0*cos (angle), r0*sin (angle), width*0.5); + glVertex3f (r1*cos (angle), r1*sin (angle), width*0.5); + glVertex3f (r0*cos (angle), r0*sin (angle), width*0.5); + glVertex3f (r1*cos (angle+3*da), r1*sin (angle+3*da), width*0.5); + } + glEnd (); + + /* draw front sides of teeth */ + glBegin (GL_QUADS); + da = 2.0*M_PI / teeth / 4.0; + for (i=0; i<teeth; i++) + { + angle = i * 2.0*M_PI / teeth; + + glVertex3f (r1*cos (angle), r1*sin (angle), width*0.5); + glVertex3f (r2*cos (angle+da), r2*sin (angle+da), width*0.5); + glVertex3f (r2*cos (angle+2*da), r2*sin (angle+2*da), width*0.5); + glVertex3f (r1*cos (angle+3*da), r1*sin (angle+3*da), width*0.5); + } + glEnd (); + + + glNormal3f (0.0, 0.0, -1.0); + + /* draw back face */ + glBegin (GL_QUAD_STRIP); + for (i=0; i<=teeth ;i++) + { + angle = i * 2.0*M_PI / teeth; + glVertex3f (r1*cos (angle), r1*sin (angle), -width*0.5); + glVertex3f (r0*cos (angle), r0*sin (angle), -width*0.5); + glVertex3f (r1*cos (angle+3*da), r1*sin (angle+3*da), -width*0.5); + glVertex3f (r0*cos (angle), r0*sin (angle), -width*0.5); + } + glEnd (); + + /* draw back sides of teeth */ + glBegin (GL_QUADS); + da = 2.0*M_PI / teeth / 4.0; + for (i=0;i<teeth;i++) + { + angle = i * 2.0*M_PI / teeth; + + glVertex3f (r1*cos (angle+3*da), r1*sin (angle+3*da), -width*0.5); + glVertex3f (r2*cos (angle+2*da), r2*sin (angle+2*da), -width*0.5); + glVertex3f (r2*cos (angle+da), r2*sin (angle+da), -width*0.5); + glVertex3f (r1*cos (angle), r1*sin (angle), -width*0.5); + } + glEnd (); + + + /* draw outward faces of teeth */ + glBegin (GL_QUAD_STRIP); + for (i=0;i<teeth;i++) + { + angle = i * 2.0*M_PI / teeth; + + glVertex3f (r1*cos (angle), r1*sin (angle), width*0.5); + glVertex3f (r1*cos (angle), r1*sin (angle), -width*0.5); + u = r2*cos (angle+da) - r1*cos (angle); + v = r2*sin (angle+da) - r1*sin (angle); + len = sqrt (u*u + v*v); + u /= len; + v /= len; + glNormal3f (v, -u, 0.0); + glVertex3f (r2*cos (angle+da), r2*sin (angle+da), width*0.5); + glVertex3f (r2*cos (angle+da), r2*sin (angle+da), -width*0.5); + glNormal3f (cos (angle), sin (angle), 0.0); + glVertex3f (r2*cos (angle+2*da), r2*sin (angle+2*da), width*0.5); + glVertex3f (r2*cos (angle+2*da), r2*sin (angle+2*da), -width*0.5); + u = r1*cos (angle+3*da) - r2*cos (angle+2*da); + v = r1*sin (angle+3*da) - r2*sin (angle+2*da); + glNormal3f (v, -u, 0.0); + glVertex3f (r1*cos (angle+3*da), r1*sin (angle+3*da), width*0.5); + glVertex3f (r1*cos (angle+3*da), r1*sin (angle+3*da), -width*0.5); + glNormal3f (cos (angle), sin (angle), 0.0); + } + + glVertex3f (r1*cos (0), r1*sin (0), width*0.5); + glVertex3f (r1*cos (0), r1*sin (0), -width*0.5); + + glEnd (); + + glShadeModel (GL_SMOOTH); + + /* draw inside radius cylinder */ + glBegin (GL_QUAD_STRIP); + for (i=0;i<=teeth;i++) + { + angle = i * 2.0*M_PI / teeth; + glNormal3f (-cos (angle), -sin (angle), 0.0); + glVertex3f (r0*cos (angle), r0*sin (angle), -width*0.5); + glVertex3f (r0*cos (angle), r0*sin (angle), width*0.5); + } + glEnd (); + +} + +UGL_LOCAL void drawGL (void) + { +#ifdef COUNT_FRAMES + int time; +#endif + + angle += 2.0; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix (); + glRotatef (view_rotx, 1.0, 0.0, 0.0); + glRotatef (view_roty, 0.0, 1.0, 0.0); + glRotatef (view_rotz, 0.0, 0.0, 1.0); + + glPushMatrix (); + glTranslatef (-3.0, -2.0, 0.0); + glRotatef (angle, 0.0, 0.0, 1.0); + glCallList (gear1); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (3.1, -2.0, 0.0); + glRotatef (-2.0*angle-9.0, 0.0, 0.0, 1.0); + glCallList (gear2); + glPopMatrix (); + + glPushMatrix (); + glTranslatef (-3.1, 4.2, 0.0); + glRotatef (-2.0*angle-25.0, 0.0, 0.0, 1.0); + glCallList (gear3); + glPopMatrix (); + + glPopMatrix (); + + uglMesaSwapBuffers (); + +#ifdef COUNT_FRAMES + if (count > limit) + { + tickStop = tickGet (); + time = (tickStop-tickStart)/tickBySec; + printf (" %i fps\n", count/time); + tickStart = tickStop; + count = 0; + } + else + count++; +#endif +} + + +UGL_LOCAL void initGL (GLsizei width, GLsizei height) + { + UGL_LOCAL GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 }; + UGL_LOCAL GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 }; + UGL_LOCAL GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 }; + UGL_LOCAL GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 }; + + glLightfv (GL_LIGHT0, GL_POSITION, pos); + glEnable (GL_CULL_FACE); + glEnable (GL_LIGHTING); + glEnable (GL_LIGHT0); + glEnable (GL_DEPTH_TEST); + + /* make the gears */ + gear1 = glGenLists (1); + glNewList (gear1, GL_COMPILE); + glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); + gear (1.0, 4.0, 1.0, 20, 0.7); + glEndList (); + + gear2 = glGenLists (1); + glNewList (gear2, GL_COMPILE); + glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); + gear (0.5, 2.0, 2.0, 10, 0.7); + glEndList (); + + gear3 = glGenLists (1); + glNewList (gear3, GL_COMPILE); + glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); + gear (1.3, 2.0, 0.5, 10, 0.7); + glEndList (); + + glEnable (GL_NORMALIZE); + + glViewport (0, 0, width, height); + + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + if (width>height) + { + GLfloat w = (GLfloat) width / (GLfloat) height; + glFrustum (-w, w, -1.0, 1.0, 5.0, 60.0); + } + else + { + GLfloat h = (GLfloat) height / (GLfloat) width; + glFrustum (-1.0, 1.0, -h, h, 5.0, 60.0); + } + + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + glTranslatef (0.0, 0.0, -40.0); + +#ifdef COUNT_FRAMES + tickStart = tickGet (); + tickBySec = sysClkRateGet (); +#endif +} + +UGL_LOCAL void echoUse(void) + { + printf("tGears keys:\n"); + printf(" z Counter clockwise rotation (z-axis)\n"); + printf(" Z Clockwise rotation (z-axis)\n"); + printf(" Up Counter clockwise rotation (x-axis)\n"); + printf(" Down Clockwise rotation (x-axis)\n"); + printf(" Left Counter clockwise rotation (y-axis)\n"); + printf(" Right Clockwise rotation (y-axis)\n"); + printf(" ESC Exit\n"); + } + + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + + switch(key) + { + case 'z': + view_rotz += 5.0; + break; + case 'Z': + view_rotz -= 5.0; + break; + case UGL_UNI_UP_ARROW: + view_rotx += 5.0; + break; + case UGL_UNI_DOWN_ARROW: + view_rotx -= 5.0; + break; + case UGL_UNI_LEFT_ARROW: + view_roty += 5.0; + break; + case UGL_UNI_RIGHT_ARROW: + view_roty -= 5.0; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLGears (void); + +void uglgears (void) + { + taskSpawn ("tGears", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLGears, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLGears (void) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + view_rotx=20.0; + view_roty=30.0; + view_rotz=0.0; + angle = 0.0; + limit = 100; + count = 1; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + + umc = uglMesaCreateNewContext (UGL_MESA_DOUBLE, NULL); + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext (umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL (width, height); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + + return; + } diff --git a/progs/windml/uglicotorus.c b/progs/windml/uglicotorus.c new file mode 100644 index 00000000000..46226f1e82c --- /dev/null +++ b/progs/windml/uglicotorus.c @@ -0,0 +1,311 @@ +/* uglicotorus.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* +modification history +-------------------- +01a,jun01,sra +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <ugl/uglucode.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +/* Need GLUT_SHAPES */ + +#include <GL/uglglutshapes.h> + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL GLfloat angle; +UGL_LOCAL GLboolean chaos_on; +UGL_LOCAL GLboolean color_on; + +UGL_LOCAL GLuint theIco, theTorus, theSphere, theCube; + +UGL_LOCAL void initGL + ( + int w, + int h + ) + { + glViewport(0,0,(GLsizei)w,(GLsizei)h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,60.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.0,0.0,25.0,0.0,0.0,0.0,0.0,1.0,0.0); + + glClearColor(0.0,0.0,0.0,0.0); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glEnable(GL_COLOR_MATERIAL); + + theIco = glGenLists(1); + glNewList(theIco, GL_COMPILE); + glutSolidIcosahedron(); + glEndList(); + + theTorus = glGenLists(1); + glNewList(theTorus, GL_COMPILE); + glutSolidTorus(0.2,1.0,10,10); + glEndList(); + + theSphere = glGenLists(1); + glNewList(theSphere, GL_COMPILE); + glutSolidSphere(2.5,20,20); + glEndList(); + + theCube = glGenLists(1); + glNewList(theCube, GL_COMPILE); + glutSolidCube(4.0); + glEndList(); + + } + +UGL_LOCAL void createIcoToruses + ( + int i + ) + { + glPushMatrix(); + glRotatef(angle,1.0,1.0,1.0); + glCallList(theIco); + + switch (i) + { + case 9 : + glColor3f(1.0,0.0,0.0); + break; + case 0 : + glColor3f(1.0,0.1,0.7); + break; + case 1 : + glColor3f(1.0,0.0,1.0); + break; + case 2 : + glColor3f(0.0,0.0,1.0); + break; + case 3 : + glColor3f(0.0,0.5,1.0); + break; + case 4 : + glColor3f(0.0,1.0,0.7); + break; + case 5 : + glColor3f(0.0,1.0,0.0); + break; + case 6 : + glColor3f(0.5,1.0,0.0); + break; + case 7 : + glColor3f(1.0,1.0,0.0); + break; + case 8 : + glColor3f(1.0,0.5,0.0); + break; + } + + glRotatef(angle,1.0,1.0,1.0); + glCallList(theTorus); + glRotatef(-2*angle,1.0,1.0,1.0); + glCallList(theTorus); + glPopMatrix(); + } + +UGL_LOCAL void drawGL (void) + { + int i; + + if (color_on) + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + else + glClear(GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + + if (chaos_on) + glRotatef(angle,1.0,1.0,1.0); + + glPushMatrix(); + glRotatef(angle,1.0,1.0,1.0); + glColor3f(1.0,0.5,0.0); + glCallList(theSphere); + glColor3f(1.0,0.0,0.0); + glCallList(theCube); + glPopMatrix(); + + glRotatef(-angle,0.0,0.0,1.0); + glPushMatrix(); + /* draw ten icosahedrons */ + for (i = 0; i < 10; i++) + { + glPushMatrix(); + glRotatef(36*i,0.0,0.0,1.0); + glTranslatef(10.0,0.0,0.0); + glRotatef(2*angle,0.0,1.0,0.0); + glTranslatef(0.0,0.0,2.0); + + createIcoToruses(i); + glPopMatrix(); + } + glPopMatrix(); + + glPopMatrix(); + + uglMesaSwapBuffers(); + + angle += 1.0; + + } + +UGL_LOCAL void echoUse(void) + { + printf("tIcoTorus keys:\n"); + printf(" c Toggle color buffer clear\n"); + printf(" SPACE Toggle chaos mode\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + + switch(key) + { + case 'c': + color_on = !color_on; + break; + case UGL_UNI_SPACE: + chaos_on = !chaos_on; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLIcoTorus (void); + +void uglicotorus (void) + { + taskSpawn ("tIcoTorus", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLIcoTorus, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLIcoTorus (void) + { + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + angle = 0.0; + chaos_on = GL_TRUE; + color_on = GL_TRUE; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + /* Double buffering */ + umc = uglMesaCreateNewContext (UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext (umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL (width, height); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext (); + uglDeinitialize (); + + return; + } + diff --git a/progs/windml/uglline.c b/progs/windml/uglline.c new file mode 100644 index 00000000000..fd100fff4b4 --- /dev/null +++ b/progs/windml/uglline.c @@ -0,0 +1,270 @@ + +/* uglline.c - WindML/Mesa example program */ + +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* +modification history +-------------------- +01a,jun01,sra Ported to UGL/Mesa and modifications +*/ + +/* +DESCRIPTION +Draw circular lines +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#define BLACK (0) +#define YELLOW (1) +#define GREEN (2) +#define BLUE (3) +#define CI_OFFSET 4 + +UGL_LOCAL GLuint rgb; +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLboolean mode1, mode2; +UGL_LOCAL GLint size; + +UGL_LOCAL GLfloat pntA[3] = { + -10.0, 0.0, 0.0 +}; +UGL_LOCAL GLfloat pntB[3] = { + -5.0, 0.0, 0.0 +}; + +UGL_LOCAL GLint angleA; + +UGL_LOCAL void initGL (void) + { + GLint i; + + uglMesaSetColor(BLACK, 0.0, 0.0, 0.0); + uglMesaSetColor(YELLOW, 1.0, 1.0, 0.0); + uglMesaSetColor(GREEN, 0.0, 1.0, 0.0); + uglMesaSetColor(BLUE, 0.0, 0.0, 1.0); + + for (i = 0; i < 16; i++) + { + uglMesaSetColor(CI_OFFSET+i, i/15.0, i/15.0, 0.0); + } + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(BLACK); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-10, 10, -10, 10, -10.0, 10.0); + + glMatrixMode(GL_MODELVIEW); + + glLineStipple(1, 0xF0E0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + mode1 = GL_FALSE; + mode2 = GL_FALSE; + size = 1; + } + +UGL_LOCAL void drawGL (void) + { + + GLint ci, i; + + glClear(GL_COLOR_BUFFER_BIT); + + glLineWidth(size); + + if (mode1) { + glEnable(GL_LINE_STIPPLE); + } else { + glDisable(GL_LINE_STIPPLE); + } + + if (mode2) { + ci = CI_OFFSET; + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + } else { + ci = YELLOW; + glDisable(GL_LINE_SMOOTH); + glDisable(GL_BLEND); + } + + glPushMatrix(); + + glRotatef(angleA, 1, 0, 1); + angleA = angleA++ % 360; + + for (i = 0; i < 360; i += 5) { + glRotatef(5.0, 0, 0, 1); + + glColor3f(1.0, 1.0, 0.0); + glBegin(GL_LINE_STRIP); + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + + glPointSize(1); + + glColor3f(0.0, 1.0, 0.0); + glBegin(GL_POINTS); + glVertex3fv(pntA); + glVertex3fv(pntB); + glEnd(); + } + + glPopMatrix(); + + glFlush(); + + uglMesaSwapBuffers(); + + } + +UGL_LOCAL void echoUse(void) + { + printf("tLine keys:\n"); + printf(" b Blending/antialiasing\n"); + printf(" n Line stipple\n"); + printf(" Up/Down Pixel size\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + switch(key) + { + case 'n': + mode1 = (mode1) ? GL_FALSE: GL_TRUE; + break; + case 'b': + mode2 = (mode2) ? GL_FALSE: GL_TRUE; + break; + case UGL_UNI_DOWN_ARROW: + if(size>0) + size--; + break; + case UGL_UNI_UP_ARROW: + size++; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLLine (void); + +void uglline (void) + { + taskSpawn("tLine", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLLine, + 0,1,2,3,4,5,6,7,8,9); + } + + +void windMLLine(void) + { + + UGL_INPUT_DEVICE_ID keyboardDevId; + + angleA = 0; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffer */ + + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy(eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglolympic.c b/progs/windml/uglolympic.c new file mode 100644 index 00000000000..de7c278b1a7 --- /dev/null +++ b/progs/windml/uglolympic.c @@ -0,0 +1,474 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +/* + * Nov 20, 1995 use stdlib's rand()/srand() instead of random()/srand48(), etc. + */ + +/* + * Modified by Stephane Raimbault to be able to run in VxWorks 07/18/01 + * + * Modified by Li Wei([email protected]) to be able to run in Windows + * 6/13 + * + * Modified by Brian Paul to compile with Windows OR Unix. 7/23/97 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <ugl/uglucode.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#ifndef RAND_MAX +# define RAND_MAX 32767 +#endif + +#define XSIZE 100 +#define YSIZE 75 + +#define RINGS 5 +#define BLUERING 0 +#define BLACKRING 1 +#define REDRING 2 +#define YELLOWRING 3 +#define GREENRING 4 + +#define BACKGROUND 8 + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL int rgb; +UGL_LOCAL unsigned char rgb_colors[RINGS][3]; +UGL_LOCAL int mapped_colors[RINGS]; +UGL_LOCAL float dests[RINGS][3]; +UGL_LOCAL float offsets[RINGS][3]; +UGL_LOCAL float angs[RINGS]; +UGL_LOCAL float rotAxis[RINGS][3]; +UGL_LOCAL int iters[RINGS]; +UGL_LOCAL GLuint theTorus; + +enum { + COLOR_BLACK = 0, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW, + COLOR_BLUE, + COLOR_MAGENTA, + COLOR_CYAN, + COLOR_WHITE +}; + +/* +UGL_LOCAL float RGBMap[9][3] = { + {0, 0, 0}, + {1, 0, 0}, + {0, 1, 0}, + {1, 1, 0}, + {0, 0, 1}, + {1, 0, 1}, + {0, 1, 1}, + {1, 1, 1}, + {0.5, 0.5, 0.5} +}; + +UGL_LOCAL void SetColor(int c) + { + (rgb) ? glColor3fv(RGBMap[c]): glIndexf(c); + } + +UGL_LOCAL void InitMap(void) + { + int i; + + if (rgb) + return; + + for (i = 0; i < 9; i++) + uglMesaSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]); + } + +UGL_LOCAL void SetFogRamp(int density, int startIndex) + { + int fogValues, colorValues; + int i, j, k; + float intensity; + + fogValues = 1 << density; + colorValues = 1 << startIndex; + for (i = 0; i < colorValues; i++) + { + for (j = 0; j < fogValues; j++) + { + k = i * fogValues + j; + intensity = (i * fogValues + j * colorValues) / 255.0; + uglMesaSetColor(k, intensity, intensity, intensity); + } + } + } + +UGL_LOCAL void SetGreyRamp(void) + { + int i; + float intensity; + + for (i = 0; i < 255; i++) + { + intensity = i / 255.0; + uglMesaSetColor(i, intensity, intensity, intensity); + } + } +*/ + +UGL_LOCAL void FillTorus(float rc, int numc, float rt, int numt) + { + int i, j, k; + double s, t; + double x, y, z; + double pi, twopi; + + pi = 3.14159265358979323846; + twopi = 2 * pi; + + for (i = 0; i < numc; i++) + { + glBegin(GL_QUAD_STRIP); + for (j = 0; j <= numt; j++) + { + for (k = 1; k >= 0; k--) + { + s = (i + k) % numc + 0.5; + t = j % numt; + + x = cos(t*twopi/numt) * cos(s*twopi/numc); + y = sin(t*twopi/numt) * cos(s*twopi/numc); + z = sin(s*twopi/numc); + glNormal3f(x, y, z); + + x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt); + y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt); + z = rc * sin(s*twopi/numc); + glVertex3f(x, y, z); + } + } + glEnd(); + } + } + +UGL_LOCAL float Clamp(int iters_left, float t) + { + if (iters_left < 3) + { + return 0.0; + } + return (iters_left-2)*t/iters_left; + } + +UGL_LOCAL void drawGL(void) + { + int i, j; + + for (i = 0; i < RINGS; i++) + { + if (iters[i]) { + for (j = 0; j < 3; j++) + { + offsets[i][j] = Clamp(iters[i], offsets[i][j]); + } + angs[i] = Clamp(iters[i], angs[i]); + iters[i]--; + } + } + + glPushMatrix(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + gluLookAt(0,0,10, 0,0,0, 0,1,0); + + for (i = 0; i < RINGS; i++) + { + if (rgb) + { + glColor3ubv(rgb_colors[i]); + } + else + { + glIndexi(mapped_colors[i]); + } + glPushMatrix(); + glTranslatef(dests[i][0]+offsets[i][0], dests[i][1]+offsets[i][1], + dests[i][2]+offsets[i][2]); + glRotatef(angs[i], rotAxis[i][0], rotAxis[i][1], rotAxis[i][2]); + glCallList(theTorus); + glPopMatrix(); + } + + glPopMatrix(); + + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL float MyRand(void) + { + return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 ); + } + +UGL_LOCAL void ReInit(void) + { + int i; + float deviation; + + deviation = MyRand() / 2; + deviation = deviation * deviation; + for (i = 0; i < RINGS; i++) + { + offsets[i][0] = MyRand(); + offsets[i][1] = MyRand(); + offsets[i][2] = MyRand(); + angs[i] = 260.0 * MyRand(); + rotAxis[i][0] = MyRand(); + rotAxis[i][1] = MyRand(); + rotAxis[i][2] = MyRand(); + iters[i] = (deviation * MyRand() + 60.0); + } + } + +UGL_LOCAL void initGL(void) + { + float base, height; + float aspect, x, y; + int i; + + float top_y = 1.0; + float bottom_y = 0.0; + float top_z = 0.15; + float bottom_z = 0.69; + float spacing = 2.5; + static float lmodel_ambient[] = {0.0, 0.0, 0.0, 0.0}; + static float lmodel_twoside[] = {GL_FALSE}; + static float lmodel_local[] = {GL_FALSE}; + static float light0_ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float light0_diffuse[] = {1.0, 1.0, 1.0, 0.0}; + static float light0_position[] = {0.8660254, 0.5, 1, 0}; + static float light0_specular[] = {1.0, 1.0, 1.0, 0.0}; + static float bevel_mat_ambient[] = {0.0, 0.0, 0.0, 1.0}; + static float bevel_mat_shininess[] = {40.0}; + static float bevel_mat_specular[] = {1.0, 1.0, 1.0, 0.0}; + static float bevel_mat_diffuse[] = {1.0, 0.0, 0.0, 0.0}; + + ReInit(); + + for (i = 0; i < RINGS; i++) + { + rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = 0; + } + rgb_colors[BLUERING][2] = 255; + rgb_colors[REDRING][0] = 255; + rgb_colors[GREENRING][1] = 255; + rgb_colors[YELLOWRING][0] = 255; + rgb_colors[YELLOWRING][1] = 255; + mapped_colors[BLUERING] = COLOR_BLUE; + mapped_colors[REDRING] = COLOR_RED; + mapped_colors[GREENRING] = COLOR_GREEN; + mapped_colors[YELLOWRING] = COLOR_YELLOW; + mapped_colors[BLACKRING] = COLOR_BLACK; + + dests[BLUERING][0] = -spacing; + dests[BLUERING][1] = top_y; + dests[BLUERING][2] = top_z; + + dests[BLACKRING][0] = 0.0; + dests[BLACKRING][1] = top_y; + dests[BLACKRING][2] = top_z; + + dests[REDRING][0] = spacing; + dests[REDRING][1] = top_y; + dests[REDRING][2] = top_z; + + dests[YELLOWRING][0] = -spacing / 2.0; + dests[YELLOWRING][1] = bottom_y; + dests[YELLOWRING][2] = bottom_z; + + dests[GREENRING][0] = spacing / 2.0; + dests[GREENRING][1] = bottom_y; + dests[GREENRING][2] = bottom_z; + + base = 2.0; + height = 2.0; + theTorus = glGenLists(1); + glNewList(theTorus, GL_COMPILE); + FillTorus(0.1, 8, 1.0, 25); + glEndList(); + + x = (float)XSIZE; + y = (float)YSIZE; + aspect = x / y; + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glEnable(GL_DEPTH_TEST); + glClearDepth(1.0); + + if (rgb) + { + glClearColor(0.5, 0.5, 0.5, 0.0); + glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular); + glLightfv(GL_LIGHT0, GL_POSITION, light0_position); + glEnable(GL_LIGHT0); + + glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glEnable(GL_LIGHTING); + + glMaterialfv(GL_FRONT, GL_AMBIENT, bevel_mat_ambient); + glMaterialfv(GL_FRONT, GL_SHININESS, bevel_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, bevel_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, bevel_mat_diffuse); + + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + glEnable(GL_COLOR_MATERIAL); + glShadeModel(GL_SMOOTH); + } + else + { + glClearIndex(BACKGROUND); + glShadeModel(GL_FLAT); + } + + glMatrixMode(GL_PROJECTION); + gluPerspective(45, 1.33, 0.1, 100.0); + glMatrixMode(GL_MODELVIEW); + } + +UGL_LOCAL void echoUse(void) + { + printf("tOlympic keys:\n"); + printf(" SPACE Reinitialize\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + switch(key) + { + case UGL_UNI_SPACE: + ReInit(); + break; + case UGL_UNI_ESCAPE: + stopWex = 1; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLOlympic (void); + +void uglolympic (void) + { + taskSpawn("tOlympic", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLOlympic, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLOlympic(void) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + echoUse(); + + stopWex = 0; + loopEvent(); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglpoint.c b/progs/windml/uglpoint.c new file mode 100644 index 00000000000..e184eaa7550 --- /dev/null +++ b/progs/windml/uglpoint.c @@ -0,0 +1,266 @@ + +/* uglpoint.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Stephane Raimbault <[email protected]> + */ + +/* +DESCRIPTION +Draw a single point. +*/ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> + +#define DOUBLE_BUFFER GL_TRUE + +enum { + BLACK = 0, + RED, + GREEN, + BLUE, + WHITE +}; + +UGL_LOCAL GLuint rgb; +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL GLint angleT; + +UGL_LOCAL void initGL (void) + { + /* By passed in RGB mode */ + uglMesaSetColor(BLACK, 0.0, 0.0, 0.0); + uglMesaSetColor(RED, 1.0, 0.0, 0.0); + uglMesaSetColor(GREEN, 0.0, 1.0, 0.0); + uglMesaSetColor(BLUE, 0.0, 0.0, 1.0); + uglMesaSetColor(WHITE, 1.0, 1.0, 1.0); + + glOrtho(0.0, 1.0, 0.0, 1.0, -20.0, 20.0); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClearIndex(BLACK); + } + +UGL_LOCAL void drawGL (void) + { + GLint i; + GLfloat x, y; + + /* Avoid blinking in single buffer */ + + if (DOUBLE_BUFFER) + glClear(GL_COLOR_BUFFER_BIT); + + /* Random points */ + + glBegin(GL_POINTS); + (rgb) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED); + + for (i=0; i<150; i++) + { + x = rand() / (RAND_MAX+1.0); + y = rand() / (RAND_MAX+1.0); + glVertex2f(x, y); + } + + (rgb) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN); + + for (i=0; i<150; i++) + { + x = (rand() / (RAND_MAX+1.0)); + y = (rand() / (RAND_MAX+1.0)); + glVertex2f(x, y); + } + + (rgb) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE); + glVertex2f(0.5,0.5); + + for (i=0; i<150; i++) + { + x = rand() / (RAND_MAX+1.0); + y = rand() / (RAND_MAX+1.0); + glVertex2f(x, y); + } + + glEnd(); + + /* Smooth triangle */ + + glPushMatrix(); + glTranslatef(0.5, 0.5, 0); + glRotatef(angleT, 1.0, -1.0, 0.0); + angleT = angleT++ % 360; + glBegin(GL_TRIANGLES); + (rgb) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED); + glVertex2f(0.75, 0.25); + (rgb) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN); + glVertex2f(0.75, 0.75); + (rgb) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE); + glVertex2f(0.25, 0.75); + glEnd(); + glPopMatrix(); + + /* Flush and swap */ + + glFlush(); + + if(DOUBLE_BUFFER) + uglMesaSwapBuffers(); + } + +/************************************************************************ +* +* getEvent +* +* RETURNS: true or false +* +* NOMANUAL +* +*/ + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLPoint (void); + +void uglpoint (void) + { + taskSpawn("tPoint", 210, VX_FP_TASK, 100000, + (FUNCPTR)windMLPoint, 0,1,2,3,4,5,6,7,8,9); + } + +void windMLPoint(void) + { + GLubyte pPixels[4]; + GLsizei width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + angleT = 0; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + if (DOUBLE_BUFFER) + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + else + umc = uglMesaCreateNewContext(UGL_MESA_SINGLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + /* RGB or CI ? */ + + uglMesaGetIntegerv(UGL_MESA_RGB, &rgb); + + initGL(); + + while (!getEvent()) + drawGL(); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + printf ("glReadPixel return "); + if (rgb) + { + glReadPixels(width/2, height/2, + 1, 1, GL_RGB, + GL_UNSIGNED_BYTE, pPixels); + glFlush(); + printf ("R:%i G:%i B:%i (RGB)", pPixels[0], pPixels[1], pPixels[2]); + } + else + { + glReadPixels(width/2, height/2, + 1, 1, GL_COLOR_INDEX, + GL_UNSIGNED_BYTE, pPixels); + glFlush(); + if (pPixels[0] == BLUE) + printf ("BLUE (CI)"); + else + printf ("%i (CI))", pPixels[0]); + } + + printf(" for %ix%i\n", width/2, height/2); + + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } diff --git a/progs/windml/uglstencil.c b/progs/windml/uglstencil.c new file mode 100644 index 00000000000..94e9f502596 --- /dev/null +++ b/progs/windml/uglstencil.c @@ -0,0 +1,233 @@ + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ +/* stencil.c + * This program draws two rotated tori in a window. + * A diamond in the center of the window masks out part + * of the scene. Within this mask, a different model + * (a sphere) is drawn in a different color. + */ + +/* + * Conversion to UGL/Mesa by Stephane Raimbault, 2001 + */ + +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> +#include <GL/uglglutshapes.h> + +#define YELLOWMAT 1 +#define BLUEMAT 2 + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL void initGL (GLsizei w, GLsizei h) + { + GLfloat yellow_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; + GLfloat yellow_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + + GLfloat blue_diffuse[] = { 0.1, 0.1, 0.7, 1.0 }; + GLfloat blue_specular[] = { 0.1, 1.0, 1.0, 1.0 }; + + GLfloat position_one[] = { 1.0, 1.0, 1.0, 0.0 }; + + glNewList(YELLOWMAT, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_DIFFUSE, yellow_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, yellow_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 64.0); + glEndList(); + + glNewList(BLUEMAT, GL_COMPILE); + glMaterialfv(GL_FRONT, GL_DIFFUSE, blue_diffuse); + glMaterialfv(GL_FRONT, GL_SPECULAR, blue_specular); + glMaterialf(GL_FRONT, GL_SHININESS, 45.0); + glEndList(); + + glLightfv(GL_LIGHT0, GL_POSITION, position_one); + + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + glDepthFunc(GL_LESS); + glEnable(GL_DEPTH_TEST); + + glClearStencil(0x0); + glEnable(GL_STENCIL_TEST); + + glClear(GL_STENCIL_BUFFER_BIT); + +/* create a diamond shaped stencil area */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-3.0, 3.0, -3.0, 3.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glStencilFunc (GL_ALWAYS, 0x1, 0x1); + glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE); + glBegin(GL_QUADS); + glVertex3f (-1.0, 0.0, 0.0); + glVertex3f (0.0, 1.0, 0.0); + glVertex3f (1.0, 0.0, 0.0); + glVertex3f (0.0, -1.0, 0.0); + glEnd(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, (GLfloat) w/(GLfloat) h, 3.0, 7.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -5.0); + } + +/* Draw a sphere in a diamond-shaped section in the + * middle of a window with 2 tori. + */ +UGL_LOCAL void drawGL(void) + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); + +/* draw blue sphere where the stencil is 1 */ + glStencilFunc (GL_EQUAL, 0x1, 0x1); + glCallList (BLUEMAT); + glutSolidSphere (0.5, 15, 15); + +/* draw the tori where the stencil is not 1 */ + glStencilFunc (GL_NOTEQUAL, 0x1, 0x1); + glPushMatrix(); + glRotatef (45.0, 0.0, 0.0, 1.0); + glRotatef (45.0, 0.0, 1.0, 0.0); + glCallList (YELLOWMAT); + glutSolidTorus (0.275, 0.85, 15, 15); + glPushMatrix(); + glRotatef (90.0, 1.0, 0.0, 0.0); + glutSolidTorus (0.275, 0.85, 15, 15); + glPopMatrix(); + glPopMatrix(); + + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +void windMLStencil (void); + +void uglstencil (void) + { + taskSpawn("tStencil", 210, VX_FP_TASK, 100000, + (FUNCPTR)windMLStencil, 0,1,2,3,4,5,6,7,8,9); + } + +void windMLStencil(void) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei width, height; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + umc = uglMesaCreateNewContextExt(GL_FALSE, + 16, + 8, + 0,0,0,0, + NULL); + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + /* Fullscreen */ + + uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + drawGL(); + + while (!getEvent()); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + + return; + } + diff --git a/progs/windml/uglteapot.c b/progs/windml/uglteapot.c new file mode 100644 index 00000000000..26c766d8346 --- /dev/null +++ b/progs/windml/uglteapot.c @@ -0,0 +1,290 @@ +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Linux Magazine July 2001 + * Conversion to UGL/Mesa from GLUT by Stephane Raimbault, 2001 + */ + +#include <stdlib.h> +#include <stdio.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <ugl/uglucode.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +/* Need GLUT_SHAPES */ + +#include <GL/uglglutshapes.h> + +#ifndef PI +#define PI 3.14159265 +#endif + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; +UGL_LOCAL volatile UGL_BOOL stopWex; + +UGL_LOCAL GLint angle; +UGL_LOCAL GLfloat Sin[360], Cos[360]; +UGL_LOCAL GLfloat L0pos[]={0.0, 2.0, -1.0}; +UGL_LOCAL GLfloat L0dif[]={0.3, 0.3, 0.8}; +UGL_LOCAL GLfloat L1pos[]={2.0, 2.0, 2.0}; +UGL_LOCAL GLfloat L1dif[]={0.5, 0.5, 0.5}; +UGL_LOCAL GLfloat Mspec[3]; +UGL_LOCAL GLfloat Mshiny; +UGL_LOCAL GLuint theTeapot; + +UGL_LOCAL void calcTableCosSin() +{ + int i; + for(i=0;i<360;i++) { + Cos[i] = cos(((float)i)/180.0*PI); + Sin[i] = sin(((float)i)/180.0*PI); + } +} + +UGL_LOCAL void initGL(void) + { + glClearColor(0.0, 0.0, 0.0, 0.0); + glColor3f(1.0, 0.0, 0.0); + glEnable(GL_DEPTH_TEST); + + glShadeModel(GL_SMOOTH); + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); + glLightfv(GL_LIGHT0, GL_DIFFUSE, L0dif); + glLightfv(GL_LIGHT0, GL_SPECULAR, L0dif); + glLightfv(GL_LIGHT1, GL_DIFFUSE, L1dif); + glLightfv(GL_LIGHT1, GL_SPECULAR, L1dif); + + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Mspec); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, Mshiny); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(45.0, 1.0, 0.1, 10.0); + glMatrixMode(GL_MODELVIEW); + + theTeapot = glGenLists(1); + glNewList(theTeapot, GL_COMPILE); + glutSolidTeapot(1.0); + glEndList(); + + } + +UGL_LOCAL void drawGL() + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glLoadIdentity(); + + gluLookAt(4.5*Cos[angle], 2.0,4.5*Sin[angle],0.0,0.0,0.0,0.0, + 1.0,0.0); + glLightfv(GL_LIGHT0, GL_POSITION, L0pos); + glLightfv(GL_LIGHT1, GL_POSITION, L1pos); + + glCallList(theTeapot); + + glFlush(); + + uglMesaSwapBuffers(); + } + +UGL_LOCAL void echoUse(void) + { + printf("tTeapot keys:\n"); + printf(" Left Counter clockwise rotation (y-axis)\n"); + printf(" Right Clockwise rotation (y-axis)\n"); + printf(" j Enable/disable Light0\n"); + printf(" k Enable/disable Light1\n"); + printf(" m Add specular\n"); + printf(" l Remove specular\n"); + printf(" o Add shininess\n"); + printf(" p Remove shininess\n"); + printf(" ESC Exit\n"); + } + + +UGL_LOCAL void readKey (UGL_WCHAR key) + { + switch(key) + { + case UGL_UNI_RIGHT_ARROW: + angle +=2; + if (angle>= 360) + angle-=360; + break; + case UGL_UNI_LEFT_ARROW: + angle -=2; + if (angle<0) + angle+=360; + break; + case 'j': + glIsEnabled(GL_LIGHT0) ? + glDisable(GL_LIGHT0) : glEnable(GL_LIGHT0); + break; + case 'k': + glIsEnabled(GL_LIGHT1) ? + glDisable(GL_LIGHT1) : glEnable(GL_LIGHT1); + break; + case 'm': + Mspec[0]+=0.1; + if(Mspec[0]>1) + Mspec[0]=1; + Mspec[1]+=0.1; + if(Mspec[1]>1) + Mspec[1]=1; + Mspec[2]+=0.1; + if(Mspec[2]>1) + Mspec[2]=1; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Mspec); + break; + case 'l': + Mspec[0]-=0.1; + if(Mspec[0]>1) + Mspec[0]=1; + Mspec[1]-=0.1; + if(Mspec[1]>1) + Mspec[1]=1; + Mspec[2]-=0.1; + if(Mspec[2]>1) + Mspec[2]=1; + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Mspec); + break; + case 'o': + Mshiny -= 1; + if (Mshiny<0) + Mshiny=0; + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, Mshiny); + break; + case 'p': + Mshiny += 1; + if (Mshiny>128) + Mshiny=128; + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, Mshiny); + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +void windMLTeapot (void); + +void uglteapot (void) + { + taskSpawn ("tTeapot", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLTeapot, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLTeapot (void) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei displayWidth, displayHeight; + GLsizei x, y, w, h; + + angle = 45; + Mspec[0] = 0.5; + Mspec[1] = 0.5; + Mspec[2] = 0.5; + Mshiny = 50; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + umc = uglMesaCreateNewContext (UGL_MESA_DOUBLE, NULL); + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext (umc, 0, 0, 1, 1); + + uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH, &displayWidth); + uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT, &displayHeight); + + h = (displayHeight*2)/3; + w = h; + x = (displayWidth-w)/2; + y = (displayHeight-h)/2; + + uglMesaMoveToWindow(x, y); + uglMesaResizeToWindow(w, h); + + calcTableCosSin(); + + initGL (); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + + return; + } diff --git a/progs/windml/ugltexcube.c b/progs/windml/ugltexcube.c new file mode 100644 index 00000000000..1ce6666b65a --- /dev/null +++ b/progs/windml/ugltexcube.c @@ -0,0 +1,460 @@ + +/* ugltexcube.c - WindML/Mesa example program */ + +/* Copyright (C) 2001 by Wind River Systems, Inc */ + +/* + * Mesa 3-D graphics library + * Version: 3.5 + * + * The MIT License + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/* + * Authors: + * Stephane Raimbault <[email protected]> + */ + +/* +DESCRIPTION +Draw a textured cube +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#include <ugl/ugl.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#define IMAGE_FILE "Mesa/windmldemos/wrs_logo.bmp" + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLfloat xrot, yrot, zrot; +UGL_LOCAL GLuint texture[1]; +UGL_LOCAL GLuint theTexCube; + +typedef struct { + unsigned long sizeX; + unsigned long sizeY; + char *data; + } TEX_IMAGE; + +UGL_LOCAL void cleanUp (void); + +UGL_LOCAL GLboolean imageLoad(char *filename, TEX_IMAGE * texImage) + { + FILE * file = NULL; + unsigned long size; + unsigned long i; + unsigned short int planes; + unsigned short int bpp; + char temp; + + if ((file = fopen(filename, "rb")) == NULL) + { + printf("File Not Found : %s\n", filename); + return GL_FALSE; + } + + fseek(file, 18, SEEK_CUR); + + if ((i = fread(&texImage->sizeX, 4, 1, file)) != 1) + { + printf("Error reading width from %s.\n", filename); + return GL_FALSE; + } + + printf("Width of %s: %lu\n", filename, texImage->sizeX); + + if ((i = fread(&texImage->sizeY, 4, 1, file)) != 1) + { + printf("Error reading height from %s.\n", filename); + return GL_FALSE; + } + + printf("Height of %s: %lu\n", filename, texImage->sizeY); + size = texImage->sizeX * texImage->sizeY * 3; + + if ((fread(&planes, 2, 1, file)) != 1) + { + printf("Error reading planes from %s.\n", filename); + return GL_FALSE; + } + + if (planes != 1) + { + printf("Planes from %s is not 1: %u\n", filename, planes); + return GL_FALSE; + } + + if ((i = fread(&bpp, 2, 1, file)) != 1) + { + printf("Error reading bpp from %s.\n", filename); + return GL_FALSE; + } + + if (bpp != 24) + { + printf("Bpp from %s is not 24: %u\n", filename, bpp); + return GL_FALSE; + } + + fseek(file, 24, SEEK_CUR); + + texImage->data = (char *) malloc(size); + + if (texImage->data == NULL) + { + printf("Error allocating memory for color-corrected texImage data"); + return GL_FALSE; + } + + if ((i = fread(texImage->data, size, 1, file)) != 1) + { + printf("Error reading texImage data from %s.\n", filename); + free(texImage->data); + return GL_FALSE; + } + + /* bgr -> rgb */ + + for (i=0; i<size; i+=3) + { + temp = texImage->data[i]; + texImage->data[i] = texImage->data[i + 2]; + texImage->data[i + 2] = temp; + } + + fclose(file); + + return GL_TRUE; + } + + +UGL_LOCAL void loadGLTexture() + { + TEX_IMAGE * texImage=NULL; + + texImage = (TEX_IMAGE *) malloc(sizeof(TEX_IMAGE)); + + if (texImage == NULL) + { + printf("Error allocating space for image"); + cleanUp(); + exit(1); + } + + if (!imageLoad(IMAGE_FILE, texImage)) + { + printf("Error allocating space for image data"); + free(texImage); + cleanUp(); + exit(1); + } + + /* Create Texture */ + glGenTextures(1, &texture[0]); + glBindTexture(GL_TEXTURE_2D, texture[0]); + glTexImage2D(GL_TEXTURE_2D, 0, 3, + texImage->sizeX, texImage->sizeY, + 0, GL_RGB, GL_UNSIGNED_BYTE, texImage->data); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + free(texImage->data); + free(texImage); + } + +UGL_LOCAL void initGL(int width, int height) + { + + /* Load the texture(s) */ + loadGLTexture(); + + /* Enable texture mapping */ + glEnable(GL_TEXTURE_2D); + + /* Clear the background color to black */ + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + + glEnable(GL_CULL_FACE); + + /* Enables smooth color shading */ + glShadeModel(GL_SMOOTH); + +/* glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); */ +/* glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); */ + + theTexCube = glGenLists(1); + glNewList(theTexCube, GL_COMPILE); + + /* Choose the texture to use */ + glBindTexture(GL_TEXTURE_2D, texture[0]); + + /* Begin drawing a cube */ + glBegin(GL_QUADS); + + /* Front face (note that the texture's corners have to match the + quad's corners) */ + + /* Bottom left of the texture and quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + + /* Back Face */ + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + + + /* Top Face */ + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + /* Bottom Face */ + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + + /* Right face */ + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(1.0f, -1.0f, -1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, -1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + + + /* Left Face */ + /* Bottom Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, -1.0f); + + /* Bottom Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + + /* Top Right Of The Texture and Quad */ + glTexCoord2f(1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + + /* Top Left Of The Texture and Quad */ + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, -1.0f); + + glEnd(); /* done with the polygon */ + glEndList(); + + glMatrixMode(GL_PROJECTION); + /* Reset the projection matrix */ + glLoadIdentity(); + /* Calculate the aspect ratio of the window */ + gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + } + +UGL_LOCAL void drawGL() + { + glClear(GL_COLOR_BUFFER_BIT); + + /* Reset The View */ + glPushMatrix(); + + /* Move 8 units into the screen */ + glTranslatef(0.0f, 0.0f, -8.0f); + + /* Rotate on the X axis */ + glRotatef(xrot, 1.0f, 0.0f, 0.0f); + + /* Rotate on the Y axis */ + glRotatef(yrot, 0.0f, 1.0f, 0.0f); + + /* Rotate On The Z Axis */ + glRotatef(zrot, 0.0f, 0.0f, 1.0f); + + glCallList(theTexCube); + + glFlush(); + + uglMesaSwapBuffers(); + + glPopMatrix(); + + xrot += 1.6f; + yrot += 1.6f; + zrot += 1.6f; +} + +UGL_LOCAL int getEvent(void) + { + UGL_EVENT event; + UGL_STATUS status; + int retVal = 0; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + + while (status != UGL_STATUS_Q_EMPTY) + { + UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + retVal = 1; + + status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); + } + + return(retVal); + } + +UGL_LOCAL void cleanUp (void) + { + if (eventServiceId != UGL_NULL) + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize(); + } + +void windMLTexCube (void); + +void ugltexcube (void) + { + taskSpawn("tTexCube", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLTexCube, + 0,1,2,3,4,5,6,7,8,9); + } + + +void windMLTexCube(void) + { + GLuint width, height; + UGL_INPUT_DEVICE_ID keyboardDevId; + + uglInitialize(); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); + + if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, + (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK) + { + qId = uglEventQCreate (eventServiceId, 100); + } + else + { + eventServiceId = UGL_NULL; + } + + umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL); + + if (umc == NULL) + { + uglDeinitialize(); + return; + } + + uglMesaMakeCurrentContext(umc, 0, 0, + UGL_MESA_FULLSCREEN_WIDTH, + UGL_MESA_FULLSCREEN_HEIGHT); + + + uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); + uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); + + initGL(width, height); + + while(!getEvent()) + drawGL(); + + cleanUp(); + + return; + } + + diff --git a/progs/windml/ugltexcyl.c b/progs/windml/ugltexcyl.c new file mode 100644 index 00000000000..d83c20b2f38 --- /dev/null +++ b/progs/windml/ugltexcyl.c @@ -0,0 +1,399 @@ +/* + * Textured cylinder demo: lighting, texturing, reflection mapping. + * + * Brian Paul May 1997 This program is in the public domain. + * + * Conversion to UGL/Mesa by Stephane Raimbault + */ + +/* + * $Log: ugltexcyl.c,v $ + * Revision 1.1 2001/08/20 16:07:11 brianp + * WindML driver (Stephane Raimbault) + * + * Revision 1.5 2001/03/27 17:35:26 brianp + * set initial window pos + * + * Revision 1.4 2000/12/24 22:53:54 pesco + * * demos/Makefile.am (INCLUDES): Added -I$(top_srcdir)/util. + * * demos/Makefile.X11, demos/Makefile.BeOS-R4, demos/Makefile.cygnus: + * Essentially the same. + * Program files updated to include "readtex.c", not "../util/readtex.c". + * * demos/reflect.c: Likewise for "showbuffer.c". + * + * + * * Makefile.am (EXTRA_DIST): Added top-level regular files. + * + * * include/GL/Makefile.am (INC_X11): Added glxext.h. + * + * + * * src/GGI/include/ggi/mesa/Makefile.am (EXTRA_HEADERS): Include + * Mesa GGI headers in dist even if HAVE_GGI is not given. + * + * * configure.in: Look for GLUT and demo source dirs in $srcdir. + * + * * src/swrast/Makefile.am (libMesaSwrast_la_SOURCES): Set to *.[ch]. + * More source list updates in various Makefile.am's. + * + * * Makefile.am (dist-hook): Remove CVS directory from distribution. + * (DIST_SUBDIRS): List all possible subdirs here. + * (SUBDIRS): Only list subdirs selected for build again. + * The above two applied to all subdir Makefile.am's also. + * + * Revision 1.3 2000/09/29 23:09:39 brianp + * added fps output + * + * Revision 1.2 1999/10/21 16:39:06 brianp + * added -info command line option + * + * Revision 1.1.1.1 1999/08/19 00:55:40 jtg + * Imported sources + * + * Revision 3.3 1999/03/28 18:24:37 brianp + * minor clean-up + * + * Revision 3.2 1998/11/05 04:34:04 brianp + * moved image files to ../images/ directory + * + * Revision 3.1 1998/06/23 03:16:51 brianp + * added Point/Linear sampling menu items + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <tickLib.h> + +#include <ugl/ugl.h> +#include <ugl/uglucode.h> +#include <ugl/uglevent.h> +#include <ugl/uglinput.h> + +#include <GL/uglmesa.h> +#include <GL/glu.h> + +#include "../util/readtex.h" + +#define TEXTURE_FILE "Mesa/images/reflect.rgb" + +#define LIT 1 +#define TEXTURED 2 +#define REFLECT 3 +#define ANIMATE 10 +#define POINT_FILTER 20 +#define LINEAR_FILTER 21 +#define QUIT 100 +#define COUNT_FRAMES + +UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; +UGL_LOCAL UGL_EVENT_Q_ID qId; +UGL_LOCAL volatile UGL_BOOL stopWex; +UGL_LOCAL UGL_MESA_CONTEXT umc; + +UGL_LOCAL GLuint CylinderObj; +UGL_LOCAL GLboolean Animate; +UGL_LOCAL GLboolean linearFilter; + +UGL_LOCAL GLfloat Xrot, Yrot, Zrot; +UGL_LOCAL GLfloat DXrot, DYrot; + +UGL_LOCAL GLuint limit; +UGL_LOCAL GLuint count; +UGL_LOCAL GLuint tickStart, tickStop, tickBySec; + +UGL_LOCAL void cleanUp (void); + +UGL_LOCAL void drawGL(void) + { +#ifdef COUNT_FRAMES + int time; +#endif + + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1.0, 0.0, 0.0); + glRotatef(Yrot, 0.0, 1.0, 0.0); + glRotatef(Zrot, 0.0, 0.0, 1.0); + glScalef(5.0, 5.0, 5.0); + glCallList(CylinderObj); + + glPopMatrix(); + + uglMesaSwapBuffers(); + + if (Animate) + { + Xrot += DXrot; + Yrot += DYrot; + } + +#ifdef COUNT_FRAMES + if (count > limit) + { + tickStop = tickGet (); + time = (tickStop-tickStart)/tickBySec; + printf (" %i fps\n", count/time); + tickStart = tickStop; + count = 0; + } + else + count++; +#endif + + } + +UGL_LOCAL void echoUse(void) + { + printf("Keys:\n"); + printf(" Up/Down Rotate on Y\n"); + printf(" Left/Right Rotate on X\n"); + printf(" a Toggle animation\n"); + printf(" f Toggle point/linear filtered\n"); + printf(" l Lit\n"); + printf(" t Textured\n"); + printf(" r Reflect\n"); + printf(" ESC Exit\n"); + } + +UGL_LOCAL void readKey(UGL_WCHAR key) + { + float step = 3.0; + switch (key) + { + case 'a': + Animate = !Animate; + break; + case 'f': + if(linearFilter) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + GL_LINEAR); + } + linearFilter = !linearFilter; + break; + case 'l': + glEnable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + break; + case 't': + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + break; + case 'r': + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + break; + case UGL_UNI_UP_ARROW: + Xrot += step; + break; + case UGL_UNI_DOWN_ARROW: + Xrot -= step; + break; + case UGL_UNI_LEFT_ARROW: + Yrot += step; + break; + case UGL_UNI_RIGHT_ARROW: + Yrot -= step; + break; + case UGL_UNI_ESCAPE: + stopWex = UGL_TRUE; + break; + } + } + +UGL_LOCAL void loopEvent(void) + { + UGL_EVENT event; + UGL_INPUT_EVENT * pInputEvent; + + UGL_FOREVER + { + if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT) + != UGL_STATUS_Q_EMPTY) + { + pInputEvent = (UGL_INPUT_EVENT *)&event; + + if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD && + pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) + readKey(pInputEvent->type.keyboard.key); + } + + drawGL(); + if (stopWex) + break; + } + } + +UGL_LOCAL void initGL(void) + { + GLUquadricObj *q = gluNewQuadric(); + CylinderObj = glGenLists(1); + glNewList(CylinderObj, GL_COMPILE); + + glTranslatef(0.0, 0.0, -1.0); + + /* cylinder */ + gluQuadricNormals(q, GL_SMOOTH); + gluQuadricTexture(q, GL_TRUE); + gluCylinder(q, 0.6, 0.6, 2.0, 24, 1); + + /* end cap */ + glTranslatef(0.0, 0.0, 2.0); + gluDisk(q, 0.0, 0.6, 24, 1); + + /* other end cap */ + glTranslatef(0.0, 0.0, -2.0); + gluQuadricOrientation(q, GLU_INSIDE); + gluDisk(q, 0.0, 0.6, 24, 1); + + glEndList(); + gluDeleteQuadric(q); + + /* lighting */ + glEnable(GL_LIGHTING); + { + GLfloat gray[4] = {0.2, 0.2, 0.2, 1.0}; + GLfloat white[4] = {1.0, 1.0, 1.0, 1.0}; + GLfloat teal[4] = { 0.0, 1.0, 0.8, 1.0 }; + glMaterialfv(GL_FRONT, GL_DIFFUSE, teal); + glLightfv(GL_LIGHT0, GL_AMBIENT, gray); + glLightfv(GL_LIGHT0, GL_DIFFUSE, white); + glEnable(GL_LIGHT0); + } + + /* fitering = nearest, initially */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); + + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) + { + printf("Error: couldn't load texture image\n"); + cleanUp(); + exit(1); + } + + glEnable(GL_CULL_FACE); /* don't need Z testing for convex objects */ + + glEnable(GL_LIGHTING); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -70.0 ); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + +#ifdef COUNT_FRAMES + tickStart = tickGet (); + tickBySec = sysClkRateGet (); +#endif + + } + +UGL_LOCAL void cleanUp (void) + { + uglEventQDestroy (eventServiceId, qId); + + uglMesaDestroyContext(); + uglDeinitialize (); + } + +void windMLTexCyl (void); + +void ugltexcyl (void) + { + taskSpawn ("tTexCyl", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLTexCyl, + 0,1,2,3,4,5,6,7,8,9); + } + +void windMLTexCyl (void) + { + UGL_INPUT_DEVICE_ID keyboardDevId; + GLsizei displayWidth, displayHeight; + GLsizei x, y, w, h; + + CylinderObj = 0; + Animate = GL_TRUE; + linearFilter = GL_FALSE; + Xrot = 0.0; + Yrot = 0.0; + Zrot = 0.0; + DXrot = 1.0; + DYrot = 2.5; + limit = 100; + count = 1; + + uglInitialize (); + + uglDriverFind (UGL_KEYBOARD_TYPE, 0, + (UGL_UINT32 *)&keyboardDevId); + + uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); + + qId = uglEventQCreate (eventServiceId, 100); + + /* Double buffering */ + umc = uglMesaCreateNewContext (UGL_MESA_DOUBLE, NULL); + if (umc == NULL) + { + uglDeinitialize (); + return; + } + + uglMesaMakeCurrentContext (umc, 0, 0, 1, 1); + + uglMesaGetIntegerv(UGL_MESA_DISPLAY_WIDTH, &displayWidth); + uglMesaGetIntegerv(UGL_MESA_DISPLAY_HEIGHT, &displayHeight); + + h = (displayHeight*3)/4; + w = h; + x = (displayWidth-w)/2; + y = (displayHeight-h)/2; + + uglMesaMoveToWindow(x, y); + uglMesaResizeToWindow(w, h); + + initGL (); + + echoUse(); + + stopWex = UGL_FALSE; + loopEvent(); + + cleanUp(); + + return; + } + diff --git a/progs/windml/wrs_logo.bmp b/progs/windml/wrs_logo.bmp Binary files differnew file mode 100644 index 00000000000..9a9f04255be --- /dev/null +++ b/progs/windml/wrs_logo.bmp diff --git a/src/glu/mesa/Makefile.ugl b/src/glu/mesa/Makefile.ugl new file mode 100644 index 00000000000..fc189bd8047 --- /dev/null +++ b/src/glu/mesa/Makefile.ugl @@ -0,0 +1,96 @@ +# Mesa 3-D graphics library +# Version: 3.5 +# +# Copyright (C) 2001 Wind River Systems, Inc + +# The MIT License +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# Makefile for GLU library + +##### MACROS ##### +GLU_MAJOR = 1 +GLU_MINOR = 3 +GLU_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) + +##### RULES ##### + +include ../rules.windml + +GLU_SOURCES = \ + glu.c \ + mipmap.c \ + nurbs.c \ + nurbscrv.c \ + nurbssrf.c \ + nurbsutl.c \ + polytest.c \ + project.c \ + quadric.c \ + tess.c \ + tesselat.c \ + ../src/windml/tornado/torMesaGLUInit.c + +GLU_OBJECTS = $(GLU_SOURCES:.c=.o) +GLU_OBJNAME = $(MESA_LIBDIR)/objMesaGLU.o + +SOURCES = $(GLU_SOURCES) + +##### TARGETS ##### + +all: depend.$(CPU)$(TOOL) $(GLU_OBJNAME) + +# Make the GLU library +$(GLU_OBJNAME): $(GLU_OBJECTS) +# $(LD) -r $(GLU_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(GLU_OBJECTS) -o $(GLU_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(GLU_OBJNAME) +# $(AR) rus $(VX_LIBNAME) $(GLU_OBJNAME) + +depend.$(CPU)$(TOOL): +ifeq ($(WIND_HOST_TYPE),x86-win32) + @ $(RM) $@ + @ $(ECHO) Creating depend.$(CPU)$(TOOL) +ifneq ($(SOURCES),) + @ for %f in ($(SOURCES)) do \ + $(CC) -MM $(CFLAGS) %f >>$@ +endif +else +Makefile + @ $(RM) $@ + @ $(ECHO) "Creating depend.$(CPU)$(TOOL)" +ifneq ($(SOURCES),) + @ for FILE in $(filter-out $(NODEPENDOBJS), $(SOURCES)); \ + do \ + $(CC) -MM $(CFLAGS) $$FILE \ + | $(TCL) $(BIN_DIR)/depend.tcl $(TGT_DIR) >>$@; \ + done +endif +endif + +.PHONY = clean + +clean: +# $(AR) d $(MESA_LIBNAME) $(GLU_OBJNAME) +# $(AR) d $(VX_LIBNAME) $(GLU_OBJNAME) + $(RM) $(GLU_OBJNAME) + $(RM) $(GLU_OBJECTS) + $(RM) depend.$(CPU)$(TOOL) + +include depend.$(CPU)$(TOOL) diff --git a/src/mesa/main/Makefile.ugl b/src/mesa/main/Makefile.ugl new file mode 100644 index 00000000000..2dcca3c2155 --- /dev/null +++ b/src/mesa/main/Makefile.ugl @@ -0,0 +1,367 @@ +# Mesa 3-D graphics library +# Version: 3.5 +# +# Copyright (C) 2001 Wind River Systems, Inc + +# The MIT License +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +# Makefile for core library + +# This makefile can moved all objects files in MESA_OBJ for use with +# ld in windShell or create a library from objects files in their +# associated .c folder. +# +# For an easy inclusion of lib$(CPU)$(TOOL)GL.a in vxworks image, this +# makefile collects together all .o in an only file +# (obj$(CPU)$(TOOL)GL.o). This operation is unnecessary for +# lib$(CPU)$(TOOL)OSMesa.a and lib$(CPU)$(TOOL)UglMesa.a because they +# already contain only one file. +# +##### MACROS ##### +MESA_MAJOR=3 +MESA_MINOR=5 +MESA_TINY=0 +VERSION=$(MESA_MAJOR).$(MESA_MINOR) + +GL_MAJOR = 1 +GL_MINOR = 2 +GL_TINY = 0$(MESA_MAJOR)0$(MESA_MINOR)0$(MESA_TINY) + +##### RULES ##### + +include ..\rules.windml + +#### GL ##### + +GL_SOURCES = \ + api_arrayelt.c \ + api_loopback.c \ + api_noop.c \ + api_validate.c \ + accum.c \ + attrib.c \ + blend.c \ + buffers.c \ + clip.c \ + colortab.c \ + config.c \ + context.c \ + convolve.c \ + debug.c \ + depth.c \ + dispatch.c \ + dlist.c \ + drawpix.c \ + enable.c \ + enums.c \ + eval.c \ + extensions.c \ + feedback.c \ + fog.c \ + get.c \ + glapi.c \ + glthread.c \ + hash.c \ + hint.c \ + histogram.c \ + image.c \ + imports.c \ + light.c \ + lines.c \ + matrix.c \ + mem.c \ + mmath.c \ + pixel.c \ + points.c \ + polygon.c \ + rastpos.c \ + state.c \ + stencil.c \ + texformat.c \ + teximage.c \ + texobj.c \ + texstate.c \ + texstore.c \ + texutil.c \ + varray.c \ + vtxfmt.c \ + X86/x86.c \ + X86/common_x86.c \ + X86/3dnow.c \ + X86/sse.c \ + math/m_debug_clip.c \ + math/m_debug_norm.c \ + math/m_debug_vertex.c \ + math/m_debug_xform.c \ + math/m_eval.c \ + math/m_matrix.c \ + math/m_translate.c \ + math/m_vector.c \ + math/m_vertices.c \ + math/m_xform.c \ + array_cache/ac_context.c \ + array_cache/ac_import.c \ + swrast/s_aaline.c \ + swrast/s_aatriangle.c \ + swrast/s_accum.c \ + swrast/s_alpha.c \ + swrast/s_alphabuf.c \ + swrast/s_bitmap.c \ + swrast/s_blend.c \ + swrast/s_buffers.c \ + swrast/s_copypix.c \ + swrast/s_context.c \ + swrast/s_depth.c \ + swrast/s_drawpix.c \ + swrast/s_feedback.c \ + swrast/s_fog.c \ + swrast/s_histogram.c \ + swrast/s_imaging.c \ + swrast/s_lines.c \ + swrast/s_logic.c \ + swrast/s_masking.c \ + swrast/s_pb.c \ + swrast/s_pixeltex.c \ + swrast/s_points.c \ + swrast/s_readpix.c \ + swrast/s_scissor.c \ + swrast/s_span.c \ + swrast/s_stencil.c \ + swrast/s_texture.c \ + swrast/s_texstore.c \ + swrast/s_triangle.c \ + swrast/s_zoom.c \ + swrast_setup/ss_context.c \ + swrast_setup/ss_triangle.c \ + swrast_setup/ss_vb.c \ + tnl/t_array_api.c \ + tnl/t_array_import.c \ + tnl/t_context.c \ + tnl/t_eval_api.c \ + tnl/t_imm_alloc.c \ + tnl/t_imm_api.c \ + tnl/t_imm_debug.c \ + tnl/t_imm_dlist.c \ + tnl/t_imm_elt.c \ + tnl/t_imm_eval.c \ + tnl/t_imm_exec.c \ + tnl/t_imm_fixup.c \ + tnl/t_pipeline.c \ + tnl/t_vb_fog.c \ + tnl/t_vb_light.c \ + tnl/t_vb_normals.c \ + tnl/t_vb_points.c \ + tnl/t_vb_render.c \ + tnl/t_vb_texgen.c \ + tnl/t_vb_texmat.c \ + tnl/t_vb_vertex.c + +GL_OBJECTS = $(GL_SOURCES:.c=.o) +GL_OBJNAME = $(MESA_LIBDIR)/objMesaGL.o + +#### X86 ##### + +x86_files = \ + X86/common_x86_asm.S \ + X86/glapi_x86.S \ + X86/x86_cliptest.S \ + X86/x86_vertex.S \ + X86/x86_xform2.S \ + X86/x86_xform3.S \ + X86/x86_xform4.S \ + +x3dnow_files = \ + X86/3dnow_normal.S \ + X86/3dnow_vertex.S \ + X86/3dnow_xform1.S \ + X86/3dnow_xform2.S \ + X86/3dnow_xform3.S \ + X86/3dnow_xform4.S + +sse_files = \ + X86/sse_normal.S \ + X86/sse_vertex.S \ + X86/sse_xform1.S \ + X86/sse_xform2.S \ + X86/sse_xform3.S \ + X86/sse_xform4.S + +mmx_files = X86/mmx_blend.S + +X86_OBJNAME = $(MESA_LIBDIR)/objMesaX86.o + +##### UGL ##### + +UGL_SOURCES = \ + windml/ugl_api.c \ + windml/ugl_dd.c \ + windml/ugl_span.c \ + windml/ugl_line.c \ + windml/ugl_tri.c \ + windml/tornado/torMesaUGLInit.c + +UGL_OBJECTS = $(UGL_SOURCES:.c=.o) +UGL_OBJNAME = $(MESA_LIBDIR)/objMesaUGL.o + +##### OS ##### + +OS_SOURCES = OSmesa/osmesa.c windml/tornado/torMesaOSInit.c +OS_OBJECTS = $(OS_SOURCES:.c=.o) +OS_OBJNAME = $(MESA_LIBDIR)/objMesaOS.o + +##### GLUTSHAPES ##### + +GLUTSHAPES_SOURCES = \ + windml/ugl_glutshapes.c \ + windml/tornado/torGLUTShapesInit.c + +GLUTSHAPES_OBJECTS = $(GLUTSHAPES_SOURCES:.c=.o) +GLUTSHAPES_OBJNAME = $(MESA_LIBDIR)/objGLUTShapes.o + +SOURCES = $(GL_SOURCES) $(UGL_SOURCES) $(OS_SOURCES) \ + $(GLUTSHAPES_SOURCES) + +##### TARGETS ##### + +all: depend.$(CPU)$(TOOL) cfgX86 $(X86_OBJNAME) $(GL_OBJNAME)\ +$(UGL_OBJNAME) $(OS_OBJNAME) $(GLUTSHAPES_OBJNAME) + +#histogram.o: +# $(CC) $(CFLAGS) -O1 $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< + +#image.o: +# $(CC) $(CFLAGS) -O1 $(OPTION_OBJECT_ONLY) $(OPTION_OBJECT_NAME)$@ $< + +cfgX86: +ifdef HAVE_3DNOW +x3dnow_sources = $(x3dnow_files) +CFLAGS_3DNOW = -DUSE_3DNOW_ASM +HAVE_X86 = 1 +endif +ifdef HAVE_SSE +sse_sources = $(sse_files) +CFLAGS_SSE = -DUSE_SSE_ASM +HAVE_X86 = 1 +endif +ifdef HAVE_MMX +mmx_sources = $(mmx_files) +CFLAGS_MMX = -DUSE_MMX_ASM +HAVE_X86 = 1 +endif +ifdef HAVE_X86 +x86_sources = $(x86_files) +CFLAGS_X86 = -DUSE_X86_ASM +endif +X86_SOURCES = $(x86_sources) $(mmx_sources) \ + $(x3dnow_sources) $(sse_sources) +X86_OBJECTS = $(X86_SOURCES:.S=.o) +CFLAGS_USE_X86 = $(CFLAGS_3DNOW) $(CFLAGS_SSE) $(CFLAGS_MMX) $(CFLAGS_X86) + +#X86/matypes.h: mtypes.h tnl/t_context.h X86/gen_matypes.c +# $(CC) -I ./ X86/gen_matypes.c -o X86/gen_matypes +# ./X86/gen_matypes > X86/matypes.h +# $(RM) X86/gen_matypes +# $(RM) X86/gen_matypes.o + +# Make the Mesax86 library +$(X86_OBJNAME): $(X86_OBJECTS) +ifdef HAVE_X86 +# $(LD) -r $(X86_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(X86_OBJECTS) -o $(X86_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(X86_OBJNAME) +# $(RM) $(X86_OBJNAME) +endif + +# Make the GL library +$(GL_OBJNAME): $(GL_OBJECTS) +# $(LD) -r $(GL_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(GL_OBJECTS) -o $(GL_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(GL_OBJNAME) +# $(AR) rus $(VX_LIBNAME) $(GL_OBJNAME) +# $(RM) $(GL_OBJNAME) + +# Make the UGLMesa library +$(UGL_OBJNAME): $(UGL_OBJECTS) +# $(LD) -r $(UGL_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(UGL_OBJECTS) -o $(UGL_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(UGL_OBJNAME) +# $(AR) rus $(VX_LIBNAME) $(UGL_OBJNAME) +# $(RM) $(UGL_OBJNAME) + +# Make the OSMesa library +$(OS_OBJNAME): $(OS_OBJECTS) +# $(LD) -r $(OS_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(OS_OBJECTS) -o $(OS_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(OS_OBJNAME) +# $(AR) rus $(VX_LIBNAME) $(OS_OBJNAME) +# $(RM) $(OS_OBJNAME) + +# Make the GLUT Shapes library +$(GLUTSHAPES_OBJNAME): $(GLUTSHAPES_OBJECTS) +# $(LD) -r $(GLUTSHAPES_OBJECTS) -o $(MESA_OBJNAME) + $(LD) -r $(GLUTSHAPES_OBJECTS) -o $(GLUTSHAPES_OBJNAME) +# $(AR) rus $(MESA_LIBNAME) $(GLUTSHAPES_OBJNAME) +# $(AR) rus $(VX_LIBNAME) $(GLUTSHAPES_OBJNAME) +# $(RM) $(GLUTSHAPES_OBJNAME) + +depend.$(CPU)$(TOOL): +ifeq ($(WIND_HOST_TYPE),x86-win32) + @ $(RM) $@ + @ $(ECHO) Creating depend.$(CPU)$(TOOL) +ifneq ($(SOURCES),) + @ for %f in ($(SOURCES)) do \ + $(CC) -MM $(CFLAGS) %f >>$@ +endif +else +Makefile + @ $(RM) $@ + @ $(ECHO) "Creating depend.$(CPU)$(TOOL)" +ifneq ($(SOURCES),) + @ for FILE in $(filter-out $(NODEPENDOBJS), $(SOURCES)); \ + do \ + $(CC) -MM $(CFLAGS) $$FILE \ + | $(TCL) $(BIN_DIR)/depend.tcl $(TGT_DIR) >>$@; \ + done +endif +endif + +.PHONY = clean + +clean: +# $(AR) d $(MESA_LIBNAME) $(GL_OBJNAME) +# $(AR) d $(MESA_LIBNAME) $(UGL_OBJNAME) +# $(AR) d $(MESA_LIBNAME) $(OS_OBJNAME) +# $(AR) d $(MESA_LIBNAME) $(GLUTSHAPES_OBJNAME) +# $(AR) d $(VX_LIBNAME) $(GL_OBJNAME) +# $(AR) d $(VX_LIBNAME) $(UGL_OBJNAME) +# $(AR) d $(VX_LIBNAME) $(OS_OBJNAME) +# $(AR) d $(VX_LIBNAME) $(GLUTSHAPES_OBJNAME) + $(RM) $(GL_OBJECTS) + $(RM) $(UGL_OBJECTS) + $(RM) $(OS_OBJECTS) + $(RM) $(GLUTSHAPES_OBJECTS) + $(RM) $(GL_OBJNAME) + $(RM) $(UGL_OBJNAME) + $(RM) $(OS_OBJNAME) + $(RM) $(GLUTSHAPES_OBJNAME) + $(RM) depend.$(CPU)$(TOOL) + +include depend.$(CPU)$(TOOL) + |