diff options
Diffstat (limited to 'demos/natives')
-rw-r--r-- | demos/natives/bc5/cube.c | 289 | ||||
-rw-r--r-- | demos/natives/bc5/cube.ide | bin | 0 -> 43014 bytes | |||
-rw-r--r-- | demos/natives/bc5/testGL1.c | 224 | ||||
-rw-r--r-- | demos/natives/bc5/testGL1.ide | bin | 0 -> 43014 bytes | |||
-rw-r--r-- | demos/natives/wgl.c | 517 | ||||
-rw-r--r-- | demos/natives/wgl.h | 81 | ||||
-rw-r--r-- | demos/natives/x11/cube.c | 95 | ||||
-rw-r--r-- | demos/natives/x11/gears.c | 374 | ||||
-rwxr-xr-x | demos/natives/x11/makeGears.sh | 3 | ||||
-rw-r--r-- | demos/natives/x11/makefile | 30 | ||||
-rw-r--r-- | demos/natives/x11/makefile.mesa | 30 | ||||
-rw-r--r-- | demos/natives/x11/makefile.x11 | 30 | ||||
-rw-r--r-- | demos/natives/x11/olympic.c | 409 | ||||
-rw-r--r-- | demos/natives/x11/testGL1.c | 222 | ||||
-rw-r--r-- | demos/natives/x11/testGL2.c | 517 | ||||
-rw-r--r-- | demos/natives/x11/wave.c | 500 |
16 files changed, 3321 insertions, 0 deletions
diff --git a/demos/natives/bc5/cube.c b/demos/natives/bc5/cube.c new file mode 100644 index 0000000..34c2f47 --- /dev/null +++ b/demos/natives/bc5/cube.c @@ -0,0 +1,289 @@ +#include <windows.h>
+#include <GL/gl.h>
+
+char *className = "OpenGL";
+char *windowName = "OpenGL Cube";
+int winX = 0, winY = 0;
+int winWidth = 300, winHeight = 300;
+
+HDC hDC;
+HGLRC hGLRC;
+HPALETTE hPalette;
+
+void
+init(void)
+{
+ /* set viewing projection */
+ glMatrixMode(GL_PROJECTION);
+ glFrustum(-0.5F, 0.5F, -0.5F, 0.5F, 1.0F, 3.0F);
+
+ /* position viewer */
+ glMatrixMode(GL_MODELVIEW);
+ glTranslatef(0.0F, 0.0F, -2.0F);
+
+ /* position object */
+ glRotatef(30.0F, 1.0F, 0.0F, 0.0F);
+ glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
+
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+}
+
+void
+redraw(void)
+{
+ /* clear color and depth buffers */
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ /* draw six faces of a cube */
+ glBegin(GL_QUADS);
+ glNormal3f( 0.0F, 0.0F, 1.0F);
+ glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F, 0.5F);
+ glVertex3f(-0.5F,-0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F);
+
+ glNormal3f( 0.0F, 0.0F,-1.0F);
+ glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F, 0.5F,-0.5F);
+ glVertex3f( 0.5F, 0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F);
+
+ glNormal3f( 0.0F, 1.0F, 0.0F);
+ glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F, 0.5F,-0.5F);
+ glVertex3f(-0.5F, 0.5F,-0.5F); glVertex3f(-0.5F, 0.5F, 0.5F);
+
+ glNormal3f( 0.0F,-1.0F, 0.0F);
+ glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f( 0.5F,-0.5F,-0.5F);
+ glVertex3f( 0.5F,-0.5F, 0.5F); glVertex3f(-0.5F,-0.5F, 0.5F);
+
+ glNormal3f( 1.0F, 0.0F, 0.0F);
+ glVertex3f( 0.5F, 0.5F, 0.5F); glVertex3f( 0.5F,-0.5F, 0.5F);
+ glVertex3f( 0.5F,-0.5F,-0.5F); glVertex3f( 0.5F, 0.5F,-0.5F);
+
+ glNormal3f(-1.0F, 0.0F, 0.0F);
+ glVertex3f(-0.5F,-0.5F,-0.5F); glVertex3f(-0.5F,-0.5F, 0.5F);
+ glVertex3f(-0.5F, 0.5F, 0.5F); glVertex3f(-0.5F, 0.5F,-0.5F);
+ glEnd();
+
+ SwapBuffers(hDC);
+}
+
+void
+resize(void)
+{
+ /* set viewport to cover the window */
+ glViewport(0, 0, winWidth, winHeight);
+}
+
+void
+setupPixelFormat(HDC hDC)
+{
+ PIXELFORMATDESCRIPTOR pfd = {
+ sizeof(PIXELFORMATDESCRIPTOR), /* size */
+ 1, /* version */
+ PFD_SUPPORT_OPENGL |
+ PFD_DRAW_TO_WINDOW |
+ PFD_DOUBLEBUFFER, /* support double-buffering */
+ PFD_TYPE_RGBA, /* color type */
+ 16, /* prefered color depth */
+ 0, 0, 0, 0, 0, 0, /* color bits (ignored) */
+ 0, /* no alpha buffer */
+ 0, /* alpha bits (ignored) */
+ 0, /* no accumulation buffer */
+ 0, 0, 0, 0, /* accum bits (ignored) */
+ 16, /* depth buffer */
+ 0, /* no stencil buffer */
+ 0, /* no auxiliary buffers */
+ PFD_MAIN_PLANE, /* main layer */
+ 0, /* reserved */
+ 0, 0, 0, /* no layer, visible, damage masks */
+ };
+ int pixelFormat;
+
+ pixelFormat = ChoosePixelFormat(hDC, &pfd);
+ if (pixelFormat == 0) {
+ MessageBox(WindowFromDC(hDC), "ChoosePixelFormat failed.", "Error",
+ MB_ICONERROR | MB_OK);
+ exit(1);
+ }
+
+ if (SetPixelFormat(hDC, pixelFormat, &pfd) != TRUE) {
+ MessageBox(WindowFromDC(hDC), "SetPixelFormat failed.", "Error",
+ MB_ICONERROR | MB_OK);
+ exit(1);
+ }
+}
+
+void
+setupPalette(HDC hDC)
+{
+ int pixelFormat = GetPixelFormat(hDC);
+ PIXELFORMATDESCRIPTOR pfd;
+ LOGPALETTE* pPal;
+ int paletteSize;
+
+ DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+
+ if (pfd.dwFlags & PFD_NEED_PALETTE) {
+ paletteSize = 1 << pfd.cColorBits;
+ } else {
+ return;
+ }
+
+ pPal = (LOGPALETTE*)
+ malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
+ pPal->palVersion = 0x300;
+ pPal->palNumEntries = paletteSize;
+
+ /* build a simple RGB color palette */
+ {
+ int redMask = (1 << pfd.cRedBits) - 1;
+ int greenMask = (1 << pfd.cGreenBits) - 1;
+ int blueMask = (1 << pfd.cBlueBits) - 1;
+ int i;
+
+ for (i=0; i<paletteSize; ++i) {
+ pPal->palPalEntry[i].peRed =
+ (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
+ pPal->palPalEntry[i].peGreen =
+ (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
+ pPal->palPalEntry[i].peBlue =
+ (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ }
+
+ hPalette = CreatePalette(pPal);
+ free(pPal);
+
+ if (hPalette) {
+ SelectPalette(hDC, hPalette, FALSE);
+ RealizePalette(hDC);
+ }
+}
+
+LRESULT APIENTRY
+WndProc(
+ HWND hWnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ switch (message) {
+ case WM_CREATE:
+ /* initialize OpenGL rendering */
+ hDC = GetDC(hWnd);
+ setupPixelFormat(hDC);
+ setupPalette(hDC);
+ hGLRC = wglCreateContext(hDC);
+ wglMakeCurrent(hDC, hGLRC);
+ init();
+ return 0;
+ case WM_DESTROY:
+ /* finish OpenGL rendering */
+ if (hGLRC) {
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(hGLRC);
+ }
+ if (hPalette) {
+ DeleteObject(hPalette);
+ }
+ ReleaseDC(hWnd, hDC);
+ PostQuitMessage(0);
+ return 0;
+ case WM_SIZE:
+ /* track window size changes */
+ if (hGLRC) {
+ winWidth = (int) LOWORD(lParam);
+ winHeight = (int) HIWORD(lParam);
+ resize();
+ return 0;
+ }
+ case WM_PALETTECHANGED:
+ /* realize palette if this is *not* the current window */
+ if (hGLRC && hPalette && (HWND) wParam != hWnd) {
+ UnrealizeObject(hPalette);
+ SelectPalette(hDC, hPalette, FALSE);
+ RealizePalette(hDC);
+ redraw();
+ break;
+ }
+ break;
+ case WM_QUERYNEWPALETTE:
+ /* realize palette if this is the current window */
+ if (hGLRC && hPalette) {
+ UnrealizeObject(hPalette);
+ SelectPalette(hDC, hPalette, FALSE);
+ RealizePalette(hDC);
+ redraw();
+ return TRUE;
+ }
+ break;
+ case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ BeginPaint(hWnd, &ps);
+ if (hGLRC) {
+ redraw();
+ }
+ EndPaint(hWnd, &ps);
+ return 0;
+ }
+ break;
+ case WM_CHAR:
+ /* handle keyboard input */
+ switch ((int)wParam) {
+ case VK_ESCAPE:
+ DestroyWindow(hWnd);
+ return 0;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ return DefWindowProc(hWnd, message, wParam, lParam);
+}
+
+int APIENTRY
+WinMain(
+ HINSTANCE hCurrentInst,
+ HINSTANCE hPreviousInst,
+ LPSTR lpszCmdLine,
+ int nCmdShow)
+{
+ WNDCLASS wndClass;
+ HWND hWnd;
+ MSG msg;
+
+ /* register window class */
+ wndClass.style = CS_HREDRAW | CS_VREDRAW;
+ wndClass.lpfnWndProc = WndProc;
+ wndClass.cbClsExtra = 0;
+ wndClass.cbWndExtra = 0;
+ wndClass.hInstance = hCurrentInst;
+ wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
+ wndClass.lpszMenuName = NULL;
+ wndClass.lpszClassName = className;
+ RegisterClass(&wndClass);
+
+ /* create window */
+ hWnd = CreateWindow(
+ className, windowName,
+ WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
+ winX, winY, winWidth, winHeight,
+ NULL, NULL, hCurrentInst, NULL);
+
+ /* display window */
+ ShowWindow(hWnd, nCmdShow);
+ UpdateWindow(hWnd);
+
+ /* process messages */
+ while (GetMessage(&msg, NULL, 0, 0) == TRUE) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ return msg.wParam;
+}
+
\ No newline at end of file diff --git a/demos/natives/bc5/cube.ide b/demos/natives/bc5/cube.ide Binary files differnew file mode 100644 index 0000000..d2fab99 --- /dev/null +++ b/demos/natives/bc5/cube.ide diff --git a/demos/natives/bc5/testGL1.c b/demos/natives/bc5/testGL1.c new file mode 100644 index 0000000..b0094f1 --- /dev/null +++ b/demos/natives/bc5/testGL1.c @@ -0,0 +1,224 @@ +
+
+
+
+ #include <windows.h>
+
+ #include <stdio.h>
+ #include <stdlib.h>
+
+#include <GL/gl.h>
+#include <GL/glut.h>
+
+double width = 250;
+double height = 250;
+double fps = 25.0;
+
+ static float lmodel_twoside[] =
+ {GL_FALSE};
+ static float lmodel_local[] =
+ {GL_FALSE};
+ static float lmodel_ambient[] =
+ {0.0, 0.0, 0.0, 0.0};
+
+void CylinderDraw( )
+{
+ glBegin( GL_TRIANGLE_STRIP );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f ( 1.0, 0.0, -5.0 );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f (1.000000, 0.000000, 5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, -5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, 5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, -5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, 5.000000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, -5.00000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, 5.00000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, -5.000000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, 5.00000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, -5.000000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, 5.00000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, -5.000000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, 5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, -5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, 5.000000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, -5.00000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, 5.00000);
+ glEnd();
+}
+
+void reshape(int width, int height)
+{
+ double fov = 45.0,
+ aspect = width / height,
+ near_ = 1.0,
+ far_ = 200.0;
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near_, far_ );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+}
+
+void display()
+{
+ static int FrameStep = 0;
+
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glPushMatrix();
+ glTranslatef( 0.0, 0.0, -65.0 );
+ glRotatef( 40.0+(2*FrameStep), 0.0, 0.0, 1.0 );
+ glRotatef( 190.0+(2*FrameStep), 0.0, 1.0, 0.0 );
+ glRotatef( 200.0+(FrameStep*2), 1.0, 0.0, 0.0 );
+ glPushMatrix();
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 0.0, 1.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 1.0, 0.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPopMatrix();
+
+ glutSwapBuffers();
+ /* glFlush(); */
+
+ FrameStep++;
+
+ if(FrameStep>100000) FrameStep=0;
+
+}
+
+void init()
+{
+ double fov = 45.0;
+ double aspect = width / height ;
+ double near_ = 1.0;
+ double far_ = 200.0;
+ float lightArr[4];
+ float farr[4];
+
+ /* initialize the widget */
+ glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
+ glFrontFace( GL_CW );
+ glEnable( GL_DEPTH_TEST );
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near_, far_ );
+
+ /* render three rotated cylinders */
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ /* enable lighting */
+ lightArr[0] = 1.0f; lightArr[1] = 1.0f;
+ lightArr[2] = 1.0f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_DIFFUSE, lightArr );
+ lightArr[0] = 90.0f; lightArr[1] = 90.0f;
+ lightArr[2] = 0.0f; lightArr[3] = 0.0f;
+ glLightfv( GL_LIGHT0, GL_POSITION, lightArr );
+ lightArr[0] = 0.1f; lightArr[1] = 0.1f;
+ lightArr[2] = 0.1f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_AMBIENT, lightArr );
+ glEnable( GL_LIGHT0 );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
+ glEnable( GL_LIGHTING );
+
+ /*
+ 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 );
+ */
+
+
+ glMaterialf( GL_FRONT, GL_SHININESS, 30.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_SPECULAR, farr );
+
+ farr[0] = 0.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, farr );
+
+ glMaterialf( GL_BACK, GL_SHININESS, 50.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 1.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_SPECULAR, farr );
+
+ farr[0] = 1.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_DIFFUSE, farr );
+
+}
+
+void idle()
+{
+ glutPostRedisplay();
+}
+
+int main( int argc, char **argv)
+{
+ fprintf(stderr,"1\n");
+ if(argc>2 && strcmp(argv[1], "-fps")==0)
+ {
+ fprintf(stderr,"2\n");
+ fps = atof(argv[2]);
+ argc-=2;
+ argv+=2;
+ }
+ fprintf(stderr, "Frame Per Secounds %d\n ( will be ignored this time )\n", fps);
+
+ glutInit(&argc, argv);
+ glutInitDisplayMode ( GLUT_DOUBLE
+ | GLUT_DEPTH
+ | GLUT_RGBA
+ );
+ glutInitWindowSize(width,height);
+ glutInitWindowPosition(100,100);
+ glutCreateWindow("OpenGL GLUT/NATIVE");
+ init();
+ glutDisplayFunc(display);
+ glutReshapeFunc(reshape);
+ glutIdleFunc(idle);
+ glutMainLoop();
+ return 0;
+}
+
diff --git a/demos/natives/bc5/testGL1.ide b/demos/natives/bc5/testGL1.ide Binary files differnew file mode 100644 index 0000000..d2fab99 --- /dev/null +++ b/demos/natives/bc5/testGL1.ide diff --git a/demos/natives/wgl.c b/demos/natives/wgl.c new file mode 100644 index 0000000..15119e8 --- /dev/null +++ b/demos/natives/wgl.c @@ -0,0 +1,517 @@ +/***************************************************************** + + Xmame OpenGL driver + + Written based on the x11 driver by Mike Oliphant - [email protected] + + http://www.ling.ed.ac.uk/~oliphant/glmame + + This code may be used and distributed under the terms of the + Mame license + +*****************************************************************/ +/* pretend we're x11.c otherwise display and a few other crucial things don't + get declared */ +#define __X11_C_ +#define __XOPENGL_C_ + +#define RRand(range) (random()%range) + +#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <windowsx.h>
+#include <assert.h>
+#include <string.h>
+#include <excpt.h>
+#include "common.h"
+#include "usrintrf.h"
+#include "osdepend.h"
+#include "mame.h"
+#include "driver.h"
+#include "MAME32.h"
+#include "Display.h"
+#include "Sound.h"
+#include "Keyboard.h"
+#include "Joystick.h"
+#include "Trak.h"
+#include "resource.h"
+#include "M32Util.h"
+
+#include "wgl.h" +
+/*
+#ifndef NOSEAL
+#include "SealSound.h" /* For sound devices.
+#endif
+*/
+
+struct GameOptions mame_options;
+static void MamePlayGame(); +static int page_index;
+static game_data_type* game_data;
+static int game_count;
+
+static int last_sort = 0;
+
+/* global data--know where to send messages */
+static BOOL in_emulation;
+
+/* quit after game */
+static BOOL quit;
+
+/* idle work at startup */
+static BOOL idle_work;
+static int game_index;
+ +int winwidth=640; +int winheight=480; +float fxgamma=1.0; + +static HDC thisWin;
+static HWND thisHwnd;
+/*
+static wglWnd thisCwnd;
+*/
+static HGLRC cx;
+ +static int fx=0; +static int fxwin=0; +extern int screendirty; +extern int doublebuffer; +extern int dodepth; + +/***************************************************************************
+ Function prototypes
+ ***************************************************************************/
+
+static LRESULT CALLBACK MAME32_MessageProc(HWND, UINT, WPARAM, LPARAM);
+static HWND MAME32_CreateWindow(void);
+static void MAME32_ProcessMessages(void);
+static BOOL MAME32_PumpAndReturnMessage(MSG* pMsg);
+static void MAME32_Quit(void);
+static BOOL OnMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT* pResult);
+static void OnActivateApp(HWND hWnd, BOOL fActivate, DWORD dwThreadId);
+static void OnSysCommand(HWND hWnd, UINT cmd, int x, int y);
+static void OnClose(HWND hWnd);
+
+/***************************************************************************
+ External variables
+ ***************************************************************************/
+
+/*
+struct tMAME32App MAME32App =
+{
+ { NULL }, /* m_hwndUI
+ { NULL }, /* m_hWnd
+ { "MAME32" }, /* m_pName
+ { FALSE }, /* m_bIsInitialized
+ { FALSE }, /* m_bIsActive
+ { FALSE }, /* m_bPaused
+ { FALSE }, /* m_bMMXDetected
+ { FALSE }, /* m_bUseAIMouse
+ { NULL }, /* m_pDisplay
+ { NULL }, /* m_pSound
+ { NULL }, /* m_pKeyboard
+ { NULL }, /* m_pJoystick
+ { NULL }, /* m_pTrak
+ { NULL }, /* m_pFMSynth
+
+ { MAME32_CreateWindow }, /* CreateMAMEWindow
+ { MAME32_ProcessMessages }, /* ProcessMessages
+ { MAME32_PumpAndReturnMessage }, /* PumpAndReturnMessage
+ { MAME32_Quit }, /* Quit
+ { NULL } /* detect MMX
+};
+*/
+
+/***************************************************************************
+ Internal structures
+ ***************************************************************************/
+
+/***************************************************************************
+ Internal variables
+ ***************************************************************************/
+
+static BOOL auto_pause;
+
+/***************************************************************************
+ External functions
+ ***************************************************************************/
+
+/*
+void MAME32App_init(options_type *options)
+{
+ MAME32App.m_hWnd = NULL;
+
+ MAME32App.m_bIsInitialized = FALSE;
+ MAME32App.m_bIsActive = FALSE;
+ MAME32App.m_bIsPaused = FALSE;
+
+ MAME32App.m_pDisplay = NULL;
+ MAME32App.m_pSound = NULL;
+ MAME32App.m_pKeyboard = NULL;
+ MAME32App.m_pJoystick = NULL;
+ MAME32App.m_pTrak = NULL;
+ MAME32App.m_pFMSynth = NULL;
+
+ auto_pause = options->auto_pause;
+
+ /*
+ Machine->scrbitmap is not initialized in the mame source
+ until after the call to osd_create_display().
+ This causes a problem if osd_create_display() detects an error,
+ then shows the error message box, which causes focus to change,
+ which causes OnPause() to be called, which uses Machine->scrbitmap.
+ Whew. So it needs to be set to NULL so it doesn't crash in OnPause().
+ /
+ Machine->scrbitmap = NULL;
+}
+*/
+
+
+
+/***************************************************************************
+ Internal OPENGL functions
+ ***************************************************************************/
+
+// Color Palette handle
+HPALETTE hPalette = NULL;
+// Set Pixel Format function - forward declaration
+void SetDCPixelFormat(HDC hDC);
+HPALETTE GetOpenGLPalette(HDC hDC);
+HGLRC tempRC;
+
+static HGLRC get_GC( HDC hDC )
+{
+ if( hDC == 0 )
+ return 0; /* printf( "get_GC: Error, HDC is zero\n"); */
+
+ // Select the pixel format
+ SetDCPixelFormat(hDC);
+
+ // Create palette if needed
+ hPalette = GetOpenGLPalette(hDC);
+
+ tempRC = wglCreateContext( hDC );
+
+ /* check if the context could be created */
+ if( tempRC == NULL ) {
+ /* fprintf(stderr, "getGC context could NOT be created \n"); */
+ return( 0 );
+ }
+
+ /* associated the context with the X window */
+ if( wglMakeCurrent( hDC, tempRC ) == FALSE) {
+ wglDeleteContext( tempRC );
+ return( 0 );
+ }
+
+ return tempRC;
+}
+
+// Select the pixel format for a given device context
+void SetDCPixelFormat(HDC hDC)
+{
+ int nPixelFormat=0;
+
+ static PIXELFORMATDESCRIPTOR pfd = {
+ sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure
+ 1, // Version of this structure
+ PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap)
+ PFD_SUPPORT_OPENGL | // Support OpenGL calls in window
+ PFD_DOUBLEBUFFER, // Double buffered
+ PFD_TYPE_RGBA, // RGBA Color mode
+ 24, // Want 24bit color
+ 0,0,0,0,0,0, // Not used to select mode
+ 0,0, // Not used to select mode
+ 0,0,0,0,0, // Not used to select mode
+ 32, // Size of depth buffer
+ 0, // Not used to select mode
+ 0, // Not used to select mode
+ PFD_MAIN_PLANE, // Draw in main plane
+ 0, // Not used to select mode
+ 0,0,0 }; // Not used to select mode
+
+ // Choose a pixel format that best matches that described in pfd
+ nPixelFormat = ChoosePixelFormat(hDC, &pfd);
+
+ // Set the pixel format for the device context
+ if(SetPixelFormat(hDC, nPixelFormat, &pfd)==FALSE)
+ MessageBox(thisHwnd, "could not set PixelFormat", "ERROR",
+ MB_OK|MB_ICONERROR);
+
+}
+
+
+// If necessary, creates a 3-3-2 palette for the device context listed.
+HPALETTE GetOpenGLPalette(HDC hDC)
+{
+ HPALETTE hRetPal = NULL; // Handle to palette to be created
+ PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
+ LOGPALETTE *pPal; // Pointer to memory for logical palette
+ int nPixelFormat; // Pixel format index
+ int nColors; // Number of entries in palette
+ int i; // Counting variable
+ BYTE RedRange,GreenRange,BlueRange;
+ // Range for each color entry (7,7,and 3)
+
+
+ // Get the pixel format index and retrieve the pixel format description
+ nPixelFormat = GetPixelFormat(hDC);
+ DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+
+ // Does this pixel format require a palette? If not, do not create a
+ // palette and just return NULL
+ if(!(pfd.dwFlags & PFD_NEED_PALETTE))
+ return NULL;
+
+ // Number of entries in palette. 8 bits yeilds 256 entries
+ nColors = 1 << pfd.cColorBits;
+
+ // Allocate space for a logical palette structure plus all the palette entries
+ pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors*sizeof(PALETTEENTRY));
+
+ // Fill in palette header
+ pPal->palVersion = 0x300; // Windows 3.0
+ pPal->palNumEntries = nColors; // table size
+
+ // Build mask of all 1's. This creates a number represented by having
+ // the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
+ // pfd.cBlueBits.
+ RedRange = (1 << pfd.cRedBits) -1;
+ GreenRange = (1 << pfd.cGreenBits) - 1;
+ BlueRange = (1 << pfd.cBlueBits) -1;
+
+ // Loop through all the palette entries
+ for(i = 0; i < nColors; i++)
+ {
+ // Fill in the 8-bit equivalents for each component
+ pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
+ pPal->palPalEntry[i].peRed = (unsigned char)(
+ (double) pPal->palPalEntry[i].peRed * 255.0 / RedRange);
+
+ pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
+ pPal->palPalEntry[i].peGreen = (unsigned char)(
+ (double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
+
+ pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
+ pPal->palPalEntry[i].peBlue = (unsigned char)(
+ (double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
+
+ pPal->palPalEntry[i].peFlags = (unsigned char) NULL;
+ }
+
+
+ // Create the palette
+ hRetPal = CreatePalette(pPal);
+
+ // Go ahead and select and realize the palette for this device context
+ SelectPalette(hDC,hRetPal,FALSE);
+ RealizePalette(hDC);
+
+ // Free the memory used for the logical palette structure
+ free(pPal);
+
+ // Return the handle to the new palette
+ return hRetPal;
+}
+
+
+/***************************************************************************
+ Internal functions
+ ***************************************************************************/
+
+/* Create display */ + +static BOOL Win32UI_init(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow)
+{
+ static BOOL bRegistered = FALSE;
+
+ if (bRegistered == FALSE)
+ {
+ WNDCLASS WndClass;
+
+ WndClass.style = CS_SAVEBITS | CS_BYTEALIGNCLIENT | CS_OWNDC;
+ WndClass.lpfnWndProc = MAME32_MessageProc;
+ WndClass.cbClsExtra = 0;
+ WndClass.cbWndExtra = 0;
+ WndClass.hInstance = hInstance;
+ WndClass.hIcon = LoadIcon(hInstance, MAKEINTATOM(IDI_MAME32_ICON));
+ WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ WndClass.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
+ WndClass.lpszMenuName = NULL;
+ WndClass.lpszClassName = (LPCSTR)"classMAME32";
+
+ if (RegisterClass(&WndClass) == 0)
+ return FALSE;
+ bRegistered = TRUE;
+ }
+
+ thisHwnd = CreateWindowEx(0,
+ "classMAME32",
+ "WGLMAME" ,
+ WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME | WS_BORDER,
+ CW_USEDEFAULT,
+ CW_USEDEFAULT,
+ 640, 480,
+ NULL,
+ NULL,
+ hInstance,
+ NULL);
+
+ ShowWindow(thisHwnd, nCmdShow);
+
+ /* thisCwnd.attach(thisHwnd); */
+ thisWin = GetDC(thisHwnd);
+
+ wglMakeCurrent(NULL, NULL);
+
+ /* get the graphics context for this widget */
+ if( (cx = get_GC( thisWin )) == 0 )
+ {
+ MessageBox(thisHwnd, "could not create GLContext", "ERROR",
+ MB_OK|MB_ICONERROR);
+
+ } else {
+ MessageBox(thisHwnd, "could create GLContext", "OK", MB_OK);
+ }
+
+ SetFocus(thisHwnd);
+
+ return thisHwnd!=NULL;
+}
+
+static LRESULT CALLBACK MAME32_MessageProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
+{
+ LRESULT Result = 0;
+ HDC hdc = 0;
+
+ switch(Msg)
+ {
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ return 0L;
+
+ case WM_QUIT:
+ OnClose(thisHwnd);
+ return 0;
+
+ case WM_PAINT:
+ hdc = (HDC) wParam;
+ return DefWindowProc(hWnd, Msg, wParam, lParam);
+ }
+ return DefWindowProc(hWnd, Msg, wParam, lParam);
+}
+
+
+static void OnClose(HWND hWnd)
+{
+ /* Don't call DestroyWindow, it will be called by osd_exit. */
+ wglMakeCurrent(NULL, NULL);
+ DestroyWindow(thisHwnd);
+}
+ +
+static BOOL idle_work;
+
+
+int WINAPI WinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow)
+{
+ MSG msg;
+
+ if (!Win32UI_init(hInstance, lpCmdLine, nCmdShow))
+ {
+ MessageBox(thisHwnd, "could not create window ...", "ERROR",
+ MB_OK|MB_ICONERROR);
+ OnClose(thisHwnd);
+ return 1;
+ }
+
+ /* Set the samplerate to 0 if sound is disabled,
+ this should notify mame not to "render" it (speed improvement) */
+ Machine->sample_rate = 0;
+ mame_options.samplerate = 0;
+
+ /*
+ Simplified MFC Run() alg. See mfc/src/thrdcore.cpp.
+ */
+ /* phase2: pump messages while available */
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ return 0;
+}
+
+
+void MamePlayGame()
+{
+ char buf[1000];
+ int index = 0;
+
+ if (run_game(index ,&mame_options) != 0)
+ {
+ const struct RomModule *romp = drivers[index]->rom;
+
+ /* This needs to be changed to use a window with a scrollbar
+ * because the list can be too large to fit on the screen.
+ */
+ sprintf(buf, "Unable to initialize machine emulation.\r\n\r\n"
+ "Most likely you have a corrupt ROM file.\r\n"
+ "The following files must exist in the specified\r\n"
+ "directory or .zip file for %s to run.\r\n\r\n",
+ drivers[index]->description);
+
+ sprintf(buf + strlen(buf), "Directory:\r\n");
+ GetCurrentDirectory(sizeof(buf) - strlen(buf), buf + strlen(buf));
+ sprintf(buf + strlen(buf), "\\%s\r\n\r\n", drivers[index]->name);
+ sprintf(buf + strlen(buf), "or .zip file:\r\n");
+ GetCurrentDirectory(sizeof(buf) - strlen(buf), buf + strlen(buf));
+ sprintf(buf + strlen(buf), "\\roms\\%s.zip\r\n\r\n", drivers[index]->name);
+
+ sprintf(buf + strlen(buf), "Files:\r\n");
+ while (romp->name || romp->offset || romp->length)
+ {
+ romp++; /* skip memory region definition */
+
+ while (romp->length)
+ {
+ char name[100];
+ int length;
+
+ sprintf(name, romp->name, drivers[index]->name);
+
+ length = 0;
+
+ do
+ {
+ /* ROM_RELOAD */
+ if (romp->name == (char *)-1)
+ length = 0; /* restart */
+
+ length += romp->length & ~0x80000000;
+
+ romp++;
+ } while (romp->length && (romp->name == 0 || romp->name == (char *)-1));
+
+ sprintf(buf + strlen(buf), "%-12s\t%u bytes\n", name, length);
+ }
+ }
+
+ MessageBox(thisHwnd, buf, "MAME32 Error", MB_OK | MB_ICONERROR);
+ }
+
+ in_emulation = FALSE;
+
+ if (quit)
+ {
+ PostMessage(thisHwnd, WM_CLOSE, 0, 0);
+ return;
+ }
+
+}
diff --git a/demos/natives/wgl.h b/demos/natives/wgl.h new file mode 100644 index 0000000..5ebe096 --- /dev/null +++ b/demos/natives/wgl.h @@ -0,0 +1,81 @@ +/***************************************************************************
+
+ M.A.M.E.32 - Multiple Arcade Machine Emulator for Win32
+ Win32 Portions Copyright (C) 1997-98 Michael Soderstrom and Chris Kirmse
+
+ This file is part of MAME32, and may only be used, modified and
+ distributed under the terms of the MAME license, in "readme.txt".
+ By continuing to use, modify or distribute this file you indicate
+ that you have read the license and understand and accept it fully.
+
+ ***************************************************************************/
+
+#ifndef __MAME32_H__
+#define __MAME32_H__
+
+#include <math.h>
+/*JAU #include <X11/cursorfont.h> */
+#include <windows.h>
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <wingdi.h>
+
+
+#define HANDLE_MESSAGE(hwnd, message, fn) \
+ case (message): \
+ { \
+ *pResult = HANDLE_##message((hwnd), (wParam), (lParam), (fn)); \
+ return TRUE; \
+ }
+
+#define PEEK_MESSAGE(hwnd, message, fn) \
+ case (message): \
+ { \
+ *pResult = HANDLE_##message((hwnd), (wParam), (lParam), (fn)); \
+ return FALSE; \
+ }
+
+/*
+struct tMAME32App
+{
+ HWND m_hwndUI;
+ HWND m_hWnd;
+ const char* m_Name;
+
+ BOOL m_bIsInitialized;
+ BOOL m_bIsActive;
+ BOOL m_bIsPaused;
+
+ BOOL m_bMMXDetected;
+
+ TRUE if using m_pTrak for standard analog inputs,
+ FALSE if using m_pJoystick for standard analog inputs.
+ BOOL m_bUseAIMouse;
+
+ struct OSDDisplay* m_pDisplay;
+ struct OSDSound* m_pSound;
+ struct OSDKeyboard* m_pKeyboard;
+ struct OSDJoystick* m_pJoystick;
+ struct OSDTrak* m_pTrak;
+
+ struct OSDFMSynth* m_pFMSynth;
+
+ HWND (*CreateMAMEWindow)(void);
+ void (*ProcessMessages)(void);
+ BOOL (*PumpAndReturnMessage)(MSG* pMsg);
+ void (*Quit)(void);
+ BOOL (*DetectMMX)(void);
+};
+
+extern struct tMAME32App MAME32App;
+
+*/
+
+/*
+class wglWnd : CWnd
+{
+}
+*/
+
+
+#endif
diff --git a/demos/natives/x11/cube.c b/demos/natives/x11/cube.c new file mode 100644 index 0000000..6f2fd57 --- /dev/null +++ b/demos/natives/x11/cube.c @@ -0,0 +1,95 @@ +
+/* Copyright (c) Mark J. Kilgard, 1997. */
+
+/* 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. */
+
+/* This program was requested by Patrick Earl; hopefully someone else
+ will write the equivalent Direct3D immediate mode program. */
+
+#include <GL/glut.h>
+
+GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; /* Red diffuse light. */
+GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */
+GLfloat n[6][3] = { /* Normals for the 6 faces of a cube. */
+ {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
+ {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0} };
+GLint faces[6][4] = { /* Vertex indices for the 6 faces of a cube. */
+ {0, 1, 2, 3}, {3, 2, 6, 7}, {7, 6, 5, 4},
+ {4, 5, 1, 0}, {5, 6, 2, 1}, {7, 4, 0, 3} };
+GLfloat v[8][3]; /* Will be filled in with X,Y,Z vertexes. */
+
+void
+drawBox(void)
+{
+ int i;
+
+ for (i = 0; i < 6; i++) {
+ glBegin(GL_QUADS);
+ glNormal3fv(&n[i][0]);
+ glVertex3fv(&v[faces[i][0]][0]);
+ glVertex3fv(&v[faces[i][1]][0]);
+ glVertex3fv(&v[faces[i][2]][0]);
+ glVertex3fv(&v[faces[i][3]][0]);
+ glEnd();
+ }
+}
+
+void
+display(void)
+{
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ drawBox();
+ glutSwapBuffers();
+}
+
+void
+init(void)
+{
+ /* Setup cube vertex data. */
+ v[0][0] = v[1][0] = v[2][0] = v[3][0] = -1;
+ v[4][0] = v[5][0] = v[6][0] = v[7][0] = 1;
+ v[0][1] = v[1][1] = v[4][1] = v[5][1] = -1;
+ v[2][1] = v[3][1] = v[6][1] = v[7][1] = 1;
+ v[0][2] = v[3][2] = v[4][2] = v[7][2] = 1;
+ v[1][2] = v[2][2] = v[5][2] = v[6][2] = -1;
+
+ /* Enable a single OpenGL light. */
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_POSITION, light_position);
+ glEnable(GL_LIGHT0);
+ glEnable(GL_LIGHTING);
+
+ glClearColor( 0.3f, 0.3f, 5.0f, 1.0f );
+
+ /* Use depth buffering for hidden surface elimination. */
+ glEnable(GL_DEPTH_TEST);
+
+ /* Setup the view of the cube. */
+ glMatrixMode(GL_PROJECTION);
+ gluPerspective( /* field of view in degree */ 40.0,
+ /* aspect ratio */ 1.0,
+ /* Z near */ 1.0, /* Z far */ 10.0);
+ glMatrixMode(GL_MODELVIEW);
+ gluLookAt(0.0, 0.0, 5.0, /* eye is at (0,0,5) */
+ 0.0, 0.0, 0.0, /* center is at (0,0,0) */
+ 0.0, 1.0, 0.); /* up is in positive Y direction */
+
+ /* Adjust cube position to be asthetic angle. */
+ glTranslatef(0.0, 0.0, -1.0);
+ glRotatef(60, 1.0, 0.0, 0.0);
+ glRotatef(-20, 0.0, 0.0, 1.0);
+}
+
+int
+main(int argc, char **argv)
+{
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
+ glutCreateWindow("red 3D lighted cube");
+ glutDisplayFunc(display);
+ init();
+ glutMainLoop();
+ return 0; /* ANSI C requires main to return int. */
+}
diff --git a/demos/natives/x11/gears.c b/demos/natives/x11/gears.c new file mode 100644 index 0000000..f1812ae --- /dev/null +++ b/demos/natives/x11/gears.c @@ -0,0 +1,374 @@ +/* $Id$ */ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Command line options: + * -info print GL implementation information + * + * + * Brian Paul + */ + +/* Conversion to GLUT by Mark J. Kilgard */ + +/* + * $Log$ + * Revision 1.1 2000/11/18 06:54:01 sven + * Initial revision + * + * 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.2 1999/06/03 17:07:36 brianp + * an extra quad was being drawn in front and back faces + * + * Revision 3.1 1998/11/03 02:49:10 brianp + * added fps output + * + * Revision 3.0 1998/02/14 18:42:29 brianp + * initial rev + * + */ + + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <GL/glut.h> + +#ifndef M_PI +#define M_PI 3.14159265 +#endif + +static GLint T0 = 0; +static GLint Frames = 0; + + +/** + + 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 + + **/ + +static 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); + if (i < teeth) { + 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); + if (i < teeth) { + 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(); + +} + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +static void +draw(void) +{ + 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(); + + glutSwapBuffers(); + + Frames++; + { + GLint t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 5000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + T0 = t; + Frames = 0; + } + } +} + + +static void +idle(void) +{ + angle += 2.0; + glutPostRedisplay(); +} + +/* change view angle, exit upon ESC */ +/* ARGSUSED1 */ +static void +key(unsigned char k, int x, int y) +{ + switch (k) { + case 'z': + view_rotz += 5.0; + break; + case 'Z': + view_rotz -= 5.0; + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + +/* change view angle */ +/* ARGSUSED1 */ +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + view_rotx += 5.0; + break; + case GLUT_KEY_DOWN: + view_rotx -= 5.0; + break; + case GLUT_KEY_LEFT: + view_roty += 5.0; + break; + case GLUT_KEY_RIGHT: + view_roty -= 5.0; + break; + default: + return; + } + glutPostRedisplay(); +} + +/* new window size or exposure */ +static void +reshape(int width, int height) +{ + GLfloat h = (GLfloat) height / (GLfloat) width; + + glViewport(0, 0, (GLint) width, (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -40.0); +} + +static void +init(int argc, char *argv[]) +{ + static GLfloat pos[4] = + {5.0, 5.0, 10.0, 0.0}; + static GLfloat red[4] = + {0.8, 0.1, 0.0, 1.0}; + static GLfloat green[4] = + {0.0, 0.8, 0.2, 1.0}; + static 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); + + if (argc > 1 && strcmp(argv[1], "-info")==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)); + } +} + +void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) + glutIdleFunc(idle); + else + glutIdleFunc(NULL); +} + +int main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); + + glutInitWindowPosition(0, 0); + glutInitWindowSize(300, 300); + glutCreateWindow("Gears"); + init(argc, argv); + + glutDisplayFunc(draw); + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutSpecialFunc(special); + glutVisibilityFunc(visible); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/demos/natives/x11/makeGears.sh b/demos/natives/x11/makeGears.sh new file mode 100755 index 0000000..f7c6f27 --- /dev/null +++ b/demos/natives/x11/makeGears.sh @@ -0,0 +1,3 @@ +#! /bin/sh +gcc -ogears -I/usr/X11R6/include/ gears.c \ + -lGL -lGLU -lglut -L/usr/X11R6/lib -lm diff --git a/demos/natives/x11/makefile b/demos/natives/x11/makefile new file mode 100644 index 0000000..d4e03bb --- /dev/null +++ b/demos/natives/x11/makefile @@ -0,0 +1,30 @@ +# +# Uses: Linux2.0X-glibc-pthreads-mesa3.0pthreads +# + +CC = cc + +CCINCL = -I/usr/local/include -I/usr/X11/include -I/usr/X11R6/include +CCLIBS = -L/usr/X11R6/lib -L/usr/local/lib -L/usr/X11/lib \ + -lGL -lGLU -lglut \ + -lXmu -lXt -lSM -lICE -lXext -lX11 -lXi -lXext -lX11 -lm -lpthread + + +C_APPL_FILES = cube.c olympic.c testGL1.c testGL2.c wave.c + + +.SUFFIXES : .c .o + +.c.o: + $(CC) -c -o $@ $< $(CCINCL) 2>&1 | tee -a errors + $(CC) -o ${@:.o=} $@ $(CCINCL) $(CCLIBS) 2>&1 | tee -a errors + +all: ${C_APPL_FILES:.c=.o} + + +clean: + rm -f *.o *~ errors + +cleanall: clean + rm -f ${C_APPL_FILES:.c=} + diff --git a/demos/natives/x11/makefile.mesa b/demos/natives/x11/makefile.mesa new file mode 100644 index 0000000..9068e08 --- /dev/null +++ b/demos/natives/x11/makefile.mesa @@ -0,0 +1,30 @@ +# +# Uses: Linux2.0X-glibc-pthreads-mesa3.0pthreads +# + +CC = cc + +CCINCL = -I/usr/local/include -I/usr/local/mesa/include -I/usr/X11R6/include +CCLIBS = -L/usr/X11R6/lib -L/usr/local/lib -L/usr/local/mesa/lib \ + -lGL -lGLU -lglut \ + -lXmu -lXt -lSM -lICE -lXext -lX11 -lXi -lXext -lX11 -lm -lpthread + + +C_APPL_FILES = cube.c olympic.c testGL1.c testGL2.c wave.c + + +.SUFFIXES : .c .o + +.c.o: + $(CC) -c -o $@ $< $(CCINCL) 2>&1 | tee -a errors + $(CC) -o ${@:.o=} $@ $(CCINCL) $(CCLIBS) 2>&1 | tee -a errors + +all: ${C_APPL_FILES:.c=.o} + + +clean: + rm -f *.o *~ errors + +cleanall: clean + rm -f ${C_APPL_FILES:.c=} + diff --git a/demos/natives/x11/makefile.x11 b/demos/natives/x11/makefile.x11 new file mode 100644 index 0000000..d4e03bb --- /dev/null +++ b/demos/natives/x11/makefile.x11 @@ -0,0 +1,30 @@ +# +# Uses: Linux2.0X-glibc-pthreads-mesa3.0pthreads +# + +CC = cc + +CCINCL = -I/usr/local/include -I/usr/X11/include -I/usr/X11R6/include +CCLIBS = -L/usr/X11R6/lib -L/usr/local/lib -L/usr/X11/lib \ + -lGL -lGLU -lglut \ + -lXmu -lXt -lSM -lICE -lXext -lX11 -lXi -lXext -lX11 -lm -lpthread + + +C_APPL_FILES = cube.c olympic.c testGL1.c testGL2.c wave.c + + +.SUFFIXES : .c .o + +.c.o: + $(CC) -c -o $@ $< $(CCINCL) 2>&1 | tee -a errors + $(CC) -o ${@:.o=} $@ $(CCINCL) $(CCLIBS) 2>&1 | tee -a errors + +all: ${C_APPL_FILES:.c=.o} + + +clean: + rm -f *.o *~ errors + +cleanall: clean + rm -f ${C_APPL_FILES:.c=} + diff --git a/demos/natives/x11/olympic.c b/demos/natives/x11/olympic.c new file mode 100644 index 0000000..0527d58 --- /dev/null +++ b/demos/natives/x11/olympic.c @@ -0,0 +1,409 @@ +
+/* Copyright (c) Mark J. Kilgard, 1994. */
+
+/**
+ * (c) Copyright 1993, 1994, 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <GL/glut.h>
+
+/* Some <math.h> files do not define M_PI... */
+#ifndef M_PI
+#define M_PI 3.141592654
+#endif
+
+extern double drand48(void);
+extern void srand48(long seedval);
+
+#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
+
+enum {
+ BLACK = 0,
+ RED,
+ GREEN,
+ YELLOW,
+ BLUE,
+ MAGENTA,
+ CYAN,
+ WHITE
+};
+
+typedef short Point[2];
+
+GLenum rgb, doubleBuffer, directRender;
+
+unsigned char rgb_colors[RINGS][3];
+int mapped_colors[RINGS];
+float dests[RINGS][3];
+float offsets[RINGS][3];
+float angs[RINGS];
+float rotAxis[RINGS][3];
+int iters[RINGS];
+GLuint theTorus;
+
+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 = M_PI;
+ 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();
+ }
+}
+
+float
+Clamp(int iters_left, float t)
+{
+
+ if (iters_left < 3) {
+ return 0.0;
+ }
+ return (iters_left - 2) * t / iters_left;
+}
+
+void
+Idle(void)
+{
+ int i, j;
+ int more = GL_FALSE;
+
+ 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]--;
+ more = GL_TRUE;
+ }
+ }
+ if (more) {
+ glutPostRedisplay();
+ } else {
+ glutIdleFunc(NULL);
+ }
+}
+
+void
+DrawScene(void)
+{
+ int 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();
+ if (doubleBuffer) {
+ glutSwapBuffers();
+ } else {
+ glFlush();
+ }
+}
+
+float
+MyRand(void)
+{
+ return 10.0 * (drand48() - 0.5);
+}
+
+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);
+ }
+}
+
+void
+Init(void)
+{
+ 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};
+
+ srand48(0x102342);
+ 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] = BLUE;
+ mapped_colors[REDRING] = RED;
+ mapped_colors[GREENRING] = GREEN;
+ mapped_colors[YELLOWRING] = YELLOW;
+ mapped_colors[BLACKRING] = 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;
+
+ theTorus = glGenLists(1);
+ glNewList(theTorus, GL_COMPILE);
+ FillTorus(0.1, 8, 1.0, 25);
+ glEndList();
+
+ 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);
+}
+
+void
+Reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+}
+
+/* ARGSUSED1 */
+void
+Key(unsigned char key, int x, int y)
+{
+
+ switch (key) {
+ case 27:
+ exit(0);
+ break;
+ case ' ':
+ ReInit();
+ glutIdleFunc(Idle);
+ break;
+ }
+}
+
+GLenum
+Args(int argc, char **argv)
+{
+ GLint i;
+
+ rgb = GL_TRUE;
+ doubleBuffer = GL_TRUE;
+
+ for (i = 1; i < argc; i++) {
+ if (strcmp(argv[i], "-ci") == 0) {
+ rgb = GL_FALSE;
+ } else if (strcmp(argv[i], "-rgb") == 0) {
+ rgb = GL_TRUE;
+ } else if (strcmp(argv[i], "-sb") == 0) {
+ doubleBuffer = GL_FALSE;
+ } else if (strcmp(argv[i], "-db") == 0) {
+ doubleBuffer = GL_TRUE;
+ } else {
+ printf("%s (Bad option).\n", argv[i]);
+ return GL_FALSE;
+ }
+ }
+ return GL_TRUE;
+}
+
+void
+visible(int vis)
+{
+ if (vis == GLUT_VISIBLE) {
+ glutIdleFunc(Idle);
+ } else {
+ glutIdleFunc(NULL);
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ GLenum type;
+
+ glutInitWindowSize(400, 300);
+ glutInit(&argc, argv);
+ if (Args(argc, argv) == GL_FALSE) {
+ exit(1);
+ }
+ type = (rgb) ? GLUT_RGB : GLUT_INDEX;
+ type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
+ glutInitDisplayMode(type);
+
+ glutCreateWindow("Olympic");
+
+ Init();
+
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(DrawScene);
+
+ glutVisibilityFunc(visible);
+
+ glutMainLoop();
+ return 0; /* ANSI C requires main to return int. */
+}
diff --git a/demos/natives/x11/testGL1.c b/demos/natives/x11/testGL1.c new file mode 100644 index 0000000..71f9ab2 --- /dev/null +++ b/demos/natives/x11/testGL1.c @@ -0,0 +1,222 @@ +
+
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <GL/gl.h>
+#include <GL/glut.h>
+
+double width = 250;
+double height = 250;
+double fps = 25.0;
+
+ static float lmodel_twoside[] =
+ {GL_FALSE};
+ static float lmodel_local[] =
+ {GL_FALSE};
+ static float lmodel_ambient[] =
+ {0.0, 0.0, 0.0, 0.0};
+
+void CylinderDraw( )
+{
+ glBegin( GL_TRIANGLE_STRIP );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f ( 1.0, 0.0, -5.0 );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f (1.000000, 0.000000, 5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, -5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, 5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, -5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, 5.000000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, -5.00000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, 5.00000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, -5.000000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, 5.00000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, -5.000000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, 5.00000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, -5.000000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, 5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, -5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, 5.000000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, -5.00000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, 5.00000);
+ glEnd();
+}
+
+void reshape(int width, int height)
+{
+ double fov = 45.0,
+ aspect = width / height,
+ near_ = 1.0,
+ far_ = 200.0;
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near_, far_ );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+}
+
+void display()
+{
+ static int FrameStep = 0;
+
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glPushMatrix();
+ glTranslatef( 0.0, 0.0, -65.0 );
+ glRotatef( 40.0+(2*FrameStep), 0.0, 0.0, 1.0 );
+ glRotatef( 190.0+(2*FrameStep), 0.0, 1.0, 0.0 );
+ glRotatef( 200.0+(FrameStep*2), 1.0, 0.0, 0.0 );
+ glPushMatrix();
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 0.0, 1.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 1.0, 0.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPopMatrix();
+
+ glutSwapBuffers();
+ /* glFlush(); */
+
+ FrameStep++;
+
+ if(FrameStep>100000) FrameStep=0;
+
+}
+
+void init()
+{
+ double fov = 45.0;
+ double aspect = width / height ;
+ double near_ = 1.0;
+ double far_ = 200.0;
+ float lightArr[4];
+ float farr[4];
+
+ /* initialize the widget */
+ glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
+ glFrontFace( GL_CW );
+ glEnable( GL_DEPTH_TEST );
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near_, far_ );
+
+ /* render three rotated cylinders */
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ /* enable lighting */
+ lightArr[0] = 1.0f; lightArr[1] = 1.0f;
+ lightArr[2] = 1.0f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_DIFFUSE, lightArr );
+ lightArr[0] = 90.0f; lightArr[1] = 90.0f;
+ lightArr[2] = 0.0f; lightArr[3] = 0.0f;
+ glLightfv( GL_LIGHT0, GL_POSITION, lightArr );
+ lightArr[0] = 0.1f; lightArr[1] = 0.1f;
+ lightArr[2] = 0.1f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_AMBIENT, lightArr );
+ glEnable( GL_LIGHT0 );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
+ glEnable( GL_LIGHTING );
+
+ /*
+ 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 );
+ */
+
+
+ glMaterialf( GL_FRONT, GL_SHININESS, 30.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_SPECULAR, farr );
+
+ farr[0] = 0.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, farr );
+
+ glMaterialf( GL_BACK, GL_SHININESS, 50.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 1.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_SPECULAR, farr );
+
+ farr[0] = 1.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_DIFFUSE, farr );
+
+}
+
+void idle()
+{
+ glutPostRedisplay();
+}
+
+int main( int argc, char **argv)
+{
+ fprintf(stderr,"1\n");
+ if(argc>2 && strcmp(argv[1], "-fps")==0)
+ {
+ fprintf(stderr,"2\n");
+ fps = atof(argv[2]);
+ argc-=2;
+ argv+=2;
+ }
+ fprintf(stderr, "Frame Per Secounds %d\n ( will be ignored this time )\n", fps);
+
+ glutInit(&argc, argv);
+ glutInitDisplayMode ( GLUT_DOUBLE
+ | GLUT_DEPTH
+ | GLUT_RGBA
+ );
+ glutInitWindowSize(width,height);
+ glutInitWindowPosition(100,100);
+ glutCreateWindow("OpenGL GLUT/NATIVE");
+ init();
+ glutDisplayFunc(display);
+ glutReshapeFunc(reshape);
+ glutIdleFunc(idle);
+ glutMainLoop();
+ return 0;
+}
+
diff --git a/demos/natives/x11/testGL2.c b/demos/natives/x11/testGL2.c new file mode 100644 index 0000000..335acc9 --- /dev/null +++ b/demos/natives/x11/testGL2.c @@ -0,0 +1,517 @@ +#include <stdio.h>
+#include <stdlib.h>
+#include <GL/gl.h>
+#include <GL/glx.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+Display *dpy; /* X display connection */
+Window xid; /* X window id */
+GLXContext glid; /* GL window id */
+
+double width = 250;
+double height = 250;
+double fps = 25.0;
+
+ static float lmodel_twoside[] =
+ {GL_FALSE};
+ static float lmodel_local[] =
+ {GL_FALSE};
+ static float lmodel_ambient[] =
+ {0.0, 0.0, 0.0, 0.0};
+
+void CylinderDraw( )
+{
+ glBegin( GL_TRIANGLE_STRIP );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f ( 1.0, 0.0, -5.0 );
+ glNormal3f ( 1.0, 0.0, -5.0 );
+ glVertex3f (1.000000, 0.000000, 5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, -5.000000);
+ glNormal3f (0.707107, 0.707107, -5.000000);
+ glVertex3f (0.707107, 0.707107, 5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, -5.000000);
+ glNormal3f (0.000000, 1.000000, -5.000000);
+ glVertex3f (0.000000, 1.000000, 5.000000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, -5.00000);
+ glNormal3f (-0.707107, 0.707107, -5.00000);
+ glVertex3f (-0.707107, 0.707107, 5.00000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, -5.000000);
+ glNormal3f (-1.000000, 0.000000, -5.000000);
+ glVertex3f (-1.000000, 0.000000, 5.00000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, -5.000000);
+ glNormal3f (-0.707107, -0.707107, -5.000000);
+ glVertex3f (-0.707107, -0.707107, 5.00000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, -5.000000);
+ glNormal3f (0.000000, -1.000000, -5.000000);
+ glVertex3f (0.000000, -1.000000, 5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, -5.00000);
+ glNormal3f (0.707107, -0.707107, -5.00000);
+ glVertex3f (0.707107, -0.707107, 5.000000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, -5.00000);
+ glNormal3f (1.000000, 0.000000, -5.00000);
+ glVertex3f (1.000000, 0.000000, 5.00000);
+ glEnd();
+}
+
+void reshape(int width, int height)
+{
+ double fov = 45.0,
+ aspect = width / height,
+ near = 1.0,
+ far = 200.0;
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near, far );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+}
+
+void display()
+{
+ static int FrameStep = 0;
+
+ glXWaitGL();
+ glXWaitX();
+ /* associated the context with the X window */
+ if( glXMakeCurrent( dpy, xid, glid ) == False) {
+ glXDestroyContext( display, glid );
+ fprintf(stderr,"(NO GC ASSOC)\n");
+ fflush(stderr);
+ return 1;
+ }
+
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+ glPushMatrix();
+ glTranslatef( 0.0, 0.0, -65.0 );
+ glRotatef( 40.0+(2*FrameStep), 0.0, 0.0, 1.0 );
+ glRotatef( 190.0+(2*FrameStep), 0.0, 1.0, 0.0 );
+ glRotatef( 200.0+(FrameStep*2), 1.0, 0.0, 0.0 );
+ glPushMatrix();
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 0.0, 1.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPushMatrix();
+ glRotatef( 90.0, 1.0, 0.0, 0.0 );
+ glScalef( 1.0, 1.0, 10.0 );
+ CylinderDraw( );
+ glPopMatrix();
+ glPopMatrix();
+
+ glXWaitGL();
+ glXWaitX();
+ glXSwapBuffers(dpy, xid);
+
+ glXWaitGL();
+ glXWaitX();
+ /* associated the context with the X window */
+ if( glXMakeCurrent( dpy, None, NULL ) == False) {
+ glXDestroyContext( display, glid );
+ fprintf(stderr,"(free GC failed)\n");
+ fflush(stderr);
+ return 1;
+ }
+
+ FrameStep++;
+
+ if(FrameStep>100000) FrameStep=0;
+
+}
+
+void init()
+{
+ double fov = 45.0;
+ double aspect = width / height ;
+ double near = 1.0;
+ double far = 200.0;
+ float lightArr[4];
+ float farr[4];
+
+ /* initialize the widget */
+ glClearColor( 0.8f, 0.8f, 1.0f, 1.0f );
+ glFrontFace( GL_CW );
+ glEnable( GL_DEPTH_TEST );
+
+ glViewport( 0, 0, width, height );
+
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+
+ gluPerspective( fov, aspect, near, far );
+
+ /* render three rotated cylinders */
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+
+ /* enable lighting */
+ lightArr[0] = 1.0f; lightArr[1] = 1.0f;
+ lightArr[2] = 1.0f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_DIFFUSE, lightArr );
+ lightArr[0] = 90.0f; lightArr[1] = 90.0f;
+ lightArr[2] = 0.0f; lightArr[3] = 0.0f;
+ glLightfv( GL_LIGHT0, GL_POSITION, lightArr );
+ lightArr[0] = 0.1f; lightArr[1] = 0.1f;
+ lightArr[2] = 0.1f; lightArr[3] = 1.0f;
+ glLightfv( GL_LIGHT0, GL_AMBIENT, lightArr );
+ glEnable( GL_LIGHT0 );
+
+ /*
+ glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+ */
+ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
+ glEnable( GL_LIGHTING );
+
+ /*
+ 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 );
+ */
+
+
+ glMaterialf( GL_FRONT, GL_SHININESS, 30.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_SPECULAR, farr );
+
+ farr[0] = 0.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_FRONT, GL_DIFFUSE, farr );
+
+ glMaterialf( GL_BACK, GL_SHININESS, 50.0f );
+
+ farr[0] = 0.0f; farr[1] = 0.0f; farr[2] = 1.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_SPECULAR, farr );
+
+ farr[0] = 1.0f; farr[1] = 1.0f; farr[2] = 0.0f; farr[3] = 1.0f;
+ glMaterialfv( GL_BACK, GL_DIFFUSE, farr );
+
+}
+
+
+static void GetLargeVisual(Display *dpy, XVisualInfo *bigVisualInfo);
+static XVisualInfo *findVisualGlX( Display *display);
+Window findAWindow( const char *frameName, Display *display, Window window);
+int verbose=1;
+
+main()
+{
+ XWMHints *p_xwmh=NULL;
+ Window xid2;
+ XEvent event;
+ XVisualInfo bigVisualInfo; /* largest pseudo color visual type */
+ XSetWindowAttributes attribs; /* X window attributes structure */
+ Colormap bigColormap; /* 12-bit color map */
+ unsigned long vmask; /* value mask for attributes */
+ int i;
+
+
+ /* Get the X display connection. We'll assume that the DISPLAY
+ * environment variable is "unix:0" since GL windows only run on
+ * on the local display. */
+ if(!(dpy = XOpenDisplay(""))) {
+ printf("\n can't open display connection \n");
+ exit(0);
+ }
+
+ /* GetLargeVisual(dpy, &bigVisualInfo); */
+ bigVisualInfo = * findVisualGlX(dpy);
+ printf("\n address of XVisualInfo structure = 0x%x \n", bigVisualInfo);
+ printf("\n address of Visual structure = 0x%x ", bigVisualInfo.visual);
+ printf("\n visualID = 0x%x ", bigVisualInfo.visualid);
+ printf("\n depth of visual = %d", bigVisualInfo.depth);
+ printf("\n class of visual = %d", bigVisualInfo.class);
+ printf("\n bits_per_rgb of visual = %d", bigVisualInfo.bits_per_rgb);
+ printf("\n colormap_size of visual = %d \n", bigVisualInfo.colormap_size);
+
+ attribs.event_mask =
+ ExposureMask;
+ attribs.border_pixel =
+ BlackPixel(dpy, bigVisualInfo.screen);
+ attribs.colormap =
+ XCreateColormap( dpy,
+ RootWindow( dpy, bigVisualInfo.screen ),
+ bigVisualInfo.visual,
+ AllocNone ) ;
+
+
+ attribs.background_pixel = 0xFFFFFFFF;
+
+ attribs.background_pixel =
+ BlackPixel(dpy, bigVisualInfo.screen);
+
+ attribs.border_pixmap = None;
+ attribs.background_pixmap = None;
+
+ vmask = CWColormap | CWBorderPixmap | CWBackPixmap;
+ vmask = CWEventMask | CWColormap | CWBorderPixel | CWBackPixel;
+
+ xid =
+ XCreateWindow(dpy,
+ RootWindow( dpy, bigVisualInfo.screen ),
+ 0,0, 400, 400,
+ 0,
+ bigVisualInfo.depth,
+ InputOutput, bigVisualInfo.visual,
+ vmask,
+ &attribs);
+
+ /* Name the window, map it, and flush the X buffer. */
+ XStoreName(dpy, xid, "GLWindow");
+ XMapWindow(dpy, xid);
+ XFlush(dpy);
+
+ glid = glXCreateContext( dpy, &bigVisualInfo, None, True );
+
+ /* check if the context could be created */
+ if( glid == NULL ) {
+ fprintf(stderr,"(NO GC)\n");
+ fflush(stderr);
+ return 1;
+ }
+ /* associated the context with the X window */
+ if( glXMakeCurrent( dpy, xid, glid ) == False) {
+ glXDestroyContext( display, glid );
+ fprintf(stderr,"(NO GC ASSOC)\n");
+ fflush(stderr);
+ return 1;
+ }
+
+ XFlush(dpy);
+ XRaiseWindow (dpy, xid);
+
+ xid2 = findAWindow("GLWindow", dpy, RootWindow( dpy, bigVisualInfo.screen ));
+
+ if(xid==xid2)
+ fprintf(stderr,"found win equals created win\n");
+ else
+ fprintf(stderr,"found win ** NOT ** equals created win\n");
+ fflush(stderr);
+
+ if((p_xwmh = XAllocWMHints()) == NULL)
+ {
+ fprintf(stderr,"No Mem for WMHints\n");
+ fflush(stderr);
+ exit(1);
+ }
+ p_xwmh->flags = (InputHint|StateHint);
+ p_xwmh->input = True;
+ p_xwmh->initial_state=NormalState;
+
+ XSetWMHints(dpy, xid, p_xwmh);
+
+ init();
+
+ for(;;)
+ display();
+
+ /* exit */
+ XDestroyWindow(dpy, xid);
+ XCloseDisplay(dpy);
+}
+
+/* ============================================================== */
+/* The following routine draws a constant pitch spiral,
+ * with initial radius r0, pitch p,
+ * nsteps line segments per revolution,
+ * and nrev revolutions */
+
+/* ============================================================== */
+
+void GetLargeVisual(Display *dpy, XVisualInfo *bigVisualInfo)
+{
+ XVisualInfo *visual_info; /* Info. about visual classes */
+ /*
+ * Get all visuals based on these masks
+ */
+ long vinfo_mask = VisualClassMask | VisualScreenMask;
+ XVisualInfo vtemp ; /* template for visuals to look for */
+ int i; /* counter */
+ int nitem ; /* number of visuals returned */
+
+ /*
+ * Get All PseudoColor Visuals
+ */
+ vtemp.class = PseudoColor ; /* Set PseudoColor class */
+ vtemp.screen = DefaultScreen(dpy) ; /* Set screen */
+ /*
+ * Get all visuals of the correct class on the correct screen
+ */
+ visual_info = XGetVisualInfo(dpy, vinfo_mask, &vtemp, &nitem) ;
+ /*
+ * Search for largest visual from all visual classes
+ */
+ *(bigVisualInfo) = *(visual_info);
+
+
+ /* NOTE: on GXT1000 and GXT500 family, winX does not support
+ * overlay window, so careful not to pick up overlay visual
+ * here!
+ */
+
+ for (i=0; i<nitem; i++, visual_info++) {
+ if (visual_info->colormap_size >= bigVisualInfo->colormap_size) {
+ *(bigVisualInfo) = *(visual_info);
+ }
+ }
+ /*
+ * return largest visual
+ */
+ return;
+}
+
+static XVisualInfo *findVisualGlX( Display *display )
+{
+ int visualAttribList[11];
+ XVisualInfo *visual;
+
+ /* Ask GLX for a visual that matches the attributes we want: Single
+ buffered and RGB with at least 4 bits for each component
+ */
+ visualAttribList[0] = GLX_RGBA;
+ visualAttribList[1] = GLX_RED_SIZE;
+ visualAttribList[2] = 1;
+ visualAttribList[3] = GLX_GREEN_SIZE;
+ visualAttribList[4] = 1;
+ visualAttribList[5] = GLX_BLUE_SIZE;
+ visualAttribList[6] = 1;
+ visualAttribList[7] = GLX_DOUBLEBUFFER;
+ visualAttribList[8] = GLX_DEPTH_SIZE;
+ visualAttribList[9] = 1;
+ visualAttribList[10] = None;
+
+ visual = glXChooseVisual( display,
+ DefaultScreen( display ),
+ visualAttribList );
+ fprintf(stderr, "\nused vi(ID:%d): \n screen %d, depth %d, class %d,\n clrmapsz %d, bitsPerRGB %d\n",
+ visual->visualid,
+ visual->screen,
+ visual->depth,
+ visual->class,
+ visual->colormap_size,
+ visual->bits_per_rgb );
+ fflush(stderr);
+
+ return( visual );
+}
+
+Window findAWindow( const char *frameName, Display *display, Window window)
+{
+ /* Variables used to find the correct java Window to render into */
+ Window root, parent, *children;
+ unsigned int numOfChildren;
+ char *buff;
+ int i, status;
+ Window retWindow, lastWindow;
+
+ /* debug helpers */
+ int i1, i2, i3;
+
+ XFlush(display);
+
+ status = XFetchName( display, window, &buff );
+
+ if( status )
+ {
+ if( !strcmp( frameName, buff ) )
+ {
+ /* Ok, we've found it,
+ so return the last child under this heirarchy
+ */
+ lastWindow = window;
+
+ XFlush(display);
+
+ status = XQueryTree( display, window,
+ &root, &parent, &children, &numOfChildren );
+
+ if(verbose)
+ {
+ fprintf(stderr,"\nfjw 4 (got :0x%x with %d childs)\n",
+ window, numOfChildren);
+ fflush(stderr);
+ }
+
+ i1=0;
+
+ while( status )
+ {
+ if( children == NULL )
+ {
+ XFlush(display);
+
+ if(verbose)
+ {
+ fprintf(stderr,"\nfjw 4 (FOUND LAST WINDOW 0x%x)\n",
+ lastWindow);
+ fflush(stderr);
+ }
+ return lastWindow;
+ }
+ lastWindow = children[numOfChildren-1];
+
+ status = XQueryTree( display, lastWindow,
+ &root, &parent, &children, &numOfChildren );
+
+ if(verbose)
+ {
+ fprintf(stderr,"fjw 4 (got :0x%x with %d childs)\n",
+ lastWindow, numOfChildren);
+ fflush(stderr);
+ }
+
+ XFlush(display);
+
+ }
+
+ return (Window)0;
+ }
+ }
+
+ /* If Window has no name, or if it's not equal to the java Frame window name
+ carry on searching recursivly
+ */
+ status = XQueryTree( display, window,
+ &root, &parent, &children, &numOfChildren );
+
+ XFlush(display);
+
+ if( status )
+ {
+ for( i=0; i < numOfChildren; i++ )
+ {
+ retWindow = findAWindow( frameName, display, children[ i ]);
+ if( retWindow )
+ {
+ /* Free up the child list */
+ /* XFree( children ); */
+ return retWindow;
+ }
+ }
+ }
+
+ /* Free up the child list */
+ /* if(children!=0) XFree( children ); */
+ return (Window)0;
+}
diff --git a/demos/natives/x11/wave.c b/demos/natives/x11/wave.c new file mode 100644 index 0000000..36d518d --- /dev/null +++ b/demos/natives/x11/wave.c @@ -0,0 +1,500 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include "GL/glut.h" + + +#ifndef PI +#define PI 3.14159265358979323846 +#endif + +#define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)])) +#define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX])) + + +GLenum rgb, doubleBuffer, directRender; + +GLint colorIndexes1[3]; +GLint colorIndexes2[3]; +GLenum clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; + +GLenum smooth = GL_FALSE; +GLenum lighting = GL_TRUE; +GLenum depth = GL_TRUE; +GLenum stepMode = GL_FALSE; +GLenum spinMode = GL_FALSE; +GLint contouring = 0; + +GLint widthX, widthY; +GLint checkerSize; +float height; + +GLint frames, curFrame = 0, nextFrame = 0; + +struct facet { + float color[3]; + float normal[3]; +}; +struct coord { + float vertex[3]; + float normal[3]; +}; +struct mesh { + GLint widthX, widthY; + GLint numFacets; + GLint numCoords; + GLint frames; + struct coord *coords; + struct facet *facets; +} theMesh; + +GLubyte contourTexture1[] = { + 255, 255, 255, 255, + 255, 255, 255, 255, + 255, 255, 255, 255, + 127, 127, 127, 127, +}; +GLubyte contourTexture2[] = { + 255, 255, 255, 255, + 255, 127, 127, 127, + 255, 127, 127, 127, + 255, 127, 127, 127, +}; + + +static void display(void) +{ + struct coord *coord; + struct facet *facet; + float *lastColor; + float *thisColor; + GLint i, j; + + glClear(clearMask); + + if (nextFrame || !stepMode) { + curFrame++; + } + if (curFrame >= theMesh.frames) { + curFrame = 0; + } + + if ((nextFrame || !stepMode) && spinMode) { + glRotatef(5.0, 0.0, 0.0, 1.0); + } + nextFrame = 0; + + for (i = 0; i < theMesh.widthX; i++) { + glBegin(GL_QUAD_STRIP); + lastColor = NULL; + for (j = 0; j < theMesh.widthY; j++) { + facet = GETFACET(curFrame, i, j); + if (!smooth && lighting) { + glNormal3fv(facet->normal); + } + if (lighting) { + thisColor = facet->color; + glColor3fv(facet->color); + } else { + thisColor = facet->color; + glColor3fv(facet->color); + } + + if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) { + if (lastColor) { + glEnd(); + glBegin(GL_QUAD_STRIP); + } + coord = GETCOORD(curFrame, i, j); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + coord = GETCOORD(curFrame, i+1, j); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + } + + coord = GETCOORD(curFrame, i, j+1); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + coord = GETCOORD(curFrame, i+1, j+1); + if (smooth && lighting) { + glNormal3fv(coord->normal); + } + glVertex3fv(coord->vertex); + + lastColor = thisColor; + } + glEnd(); + } + + glFlush(); + if (doubleBuffer) { + glutSwapBuffers(); + } +} + + +static void InitMesh(void) +{ + struct coord *coord; + struct facet *facet; + float dp1[3], dp2[3]; + float *pt1, *pt2, *pt3; + float angle, d, x, y; + GLint numFacets, numCoords, frameNum, i, j; + + theMesh.widthX = widthX; + theMesh.widthY = widthY; + theMesh.frames = frames; + + numFacets = widthX * widthY; + numCoords = (widthX + 1) * (widthY + 1); + + theMesh.numCoords = numCoords; + theMesh.numFacets = numFacets; + + theMesh.coords = (struct coord *)malloc(frames*numCoords* + sizeof(struct coord)); + theMesh.facets = (struct facet *)malloc(frames*numFacets* + sizeof(struct facet)); + if (theMesh.coords == NULL || theMesh.facets == NULL) { + printf("Out of memory.\n"); + exit(0); + } + + for (frameNum = 0; frameNum < frames; frameNum++) { + for (i = 0; i <= widthX; i++) { + x = i / (float)widthX; + for (j = 0; j <= widthY; j++) { + y = j / (float)widthY; + + d = sqrt(x*x+y*y); + if (d == 0.0) { + d = 0.0001; + } + angle = 2 * PI * d + (2 * PI / frames * frameNum); + + coord = GETCOORD(frameNum, i, j); + + coord->vertex[0] = x - 0.5; + coord->vertex[1] = y - 0.5; + coord->vertex[2] = (height - height * d) * cos(angle); + + coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI * + sin(angle) + cos(angle)); + coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI * + sin(angle) + cos(angle)); + coord->normal[2] = -1; + + d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+ + coord->normal[1]*coord->normal[1]+1); + coord->normal[0] *= d; + coord->normal[1] *= d; + coord->normal[2] *= d; + } + } + for (i = 0; i < widthX; i++) { + for (j = 0; j < widthY; j++) { + facet = GETFACET(frameNum, i, j); + if (((i/checkerSize)%2)^(j/checkerSize)%2) { + facet->color[0] = 1.0; + facet->color[1] = 0.2; + facet->color[2] = 0.2; + } else { + facet->color[0] = 0.2; + facet->color[1] = 1.0; + facet->color[2] = 0.2; + } + pt1 = GETCOORD(frameNum, i, j)->vertex; + pt2 = GETCOORD(frameNum, i, j+1)->vertex; + pt3 = GETCOORD(frameNum, i+1, j+1)->vertex; + + dp1[0] = pt2[0] - pt1[0]; + dp1[1] = pt2[1] - pt1[1]; + dp1[2] = pt2[2] - pt1[2]; + + dp2[0] = pt3[0] - pt2[0]; + dp2[1] = pt3[1] - pt2[1]; + dp2[2] = pt3[2] - pt2[2]; + + facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1]; + facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2]; + facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0]; + + d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+ + facet->normal[1]*facet->normal[1]+ + facet->normal[2]*facet->normal[2]); + + facet->normal[0] *= d; + facet->normal[1] *= d; + facet->normal[2] *= d; + } + } + } +} + +static void InitMaterials(void) +{ + static float ambient[] = {0.1, 0.1, 0.1, 1.0}; + static float diffuse[] = {0.5, 1.0, 1.0, 1.0}; + static float position[] = {90.0, 90.0, 150.0, 0.0}; + static float front_mat_shininess[] = {60.0}; + static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0}; + static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0}; + static float back_mat_shininess[] = {60.0}; + static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0}; + static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0}; + static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0}; + static float lmodel_twoside[] = {GL_TRUE}; + + glMatrixMode(GL_PROJECTION); + gluPerspective(450, 1.0, 0.5, 10.0); + + glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); + glLightfv(GL_LIGHT0, GL_POSITION, position); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); + glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess); + glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular); + glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse); + glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess); + glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular); + glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse); + glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + + glEnable(GL_COLOR_MATERIAL); +} + +static void InitTexture(void) +{ + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +} + +void +Idle(void) +{ + glutPostRedisplay(); +} + +static void Init(void) +{ + + glClearColor(0.0, 0.0, 0.0, 0.0); + + glShadeModel(GL_FLAT); + + glFrontFace(GL_CW); + + glEnable(GL_DEPTH_TEST); + + InitMaterials(); + InitTexture(); + InitMesh(); + + glMatrixMode(GL_MODELVIEW); + glTranslatef(0.0, 0.4, -1.8); + glScalef(2.0, 2.0, 2.0); + glRotatef(-35.0, 1.0, 0.0, 0.0); + glRotatef(35.0, 0.0, 0.0, 1.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); +} + +void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(0); break; + case 'c': + contouring++; + if (contouring == 1) { + static GLfloat map[4] = {0, 0, 20, 0}; + + glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE, + GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1); + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); + glTexGenfv(GL_S, GL_OBJECT_PLANE, map); + glTexGenfv(GL_T, GL_OBJECT_PLANE, map); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + } else if (contouring == 2) { + static GLfloat map[4] = {0, 0, 20, 0}; + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glPushMatrix(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTexGenfv(GL_S, GL_EYE_PLANE, map); + glTexGenfv(GL_T, GL_EYE_PLANE, map); + glPopMatrix(); + } else { + contouring = 0; + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_2D); + } + break; + case 's': + smooth = !smooth; + if (smooth) { + glShadeModel(GL_SMOOTH); + } else { + glShadeModel(GL_FLAT); + } + break; + case 'l': + lighting = !lighting; + if (lighting) { + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glEnable(GL_COLOR_MATERIAL); + } else { + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_COLOR_MATERIAL); + } + break; + case 'd': + depth = !depth; + if (depth) { + glEnable(GL_DEPTH_TEST); + clearMask |= GL_DEPTH_BUFFER_BIT; + } else { + glDisable(GL_DEPTH_TEST); + clearMask &= ~GL_DEPTH_BUFFER_BIT; + } + break; + case ' ': + stepMode = !stepMode; + if (stepMode) { + glutIdleFunc(0); + } else { + glutIdleFunc(Idle); + } + break; + case 'n': + if (stepMode) { + nextFrame = 1; + } + break; + case 'a': + spinMode = !spinMode; + break; + default: + return ; + } + return ; +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_TRUE; + directRender = GL_TRUE; + rgb = GL_TRUE; + frames = 10; + widthX = 10; + widthY = 10; + checkerSize = 2; + height = 0.2; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else if (strcmp(argv[i], "-dr") == 0) { + directRender = GL_TRUE; + } else if (strcmp(argv[i], "-ir") == 0) { + directRender = GL_FALSE; + } else if (strcmp(argv[i], "-grid") == 0) { + if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') { + printf("-grid (No numbers).\n"); + return GL_FALSE; + } else { + widthX = atoi(argv[++i]); + widthY = atoi(argv[++i]); + } + } else if (strcmp(argv[i], "-size") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-checker (No number).\n"); + return GL_FALSE; + } else { + checkerSize = atoi(argv[++i]); + } + } else if (strcmp(argv[i], "-wave") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-wave (No number).\n"); + return GL_FALSE; + } else { + height = atof(argv[++i]); + } + } else if (strcmp(argv[i], "-frames") == 0) { + if (i+1 >= argc || argv[i+1][0] == '-') { + printf("-frames (No number).\n"); + return GL_FALSE; + } else { + frames = atoi(argv[++i]); + } + } else { + printf("%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int +main(int argc, char **argv) +{ + GLenum type; + + glutInitWindowSize(300, 300); + glutInit(&argc, argv); + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + type = (rgb) ? GLUT_RGB : GLUT_INDEX; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + glutCreateWindow("wave"); + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutIdleFunc(Idle); + glutDisplayFunc(display); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} + |