123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
-
- /* 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 <stephane.raimbault@windriver.com>
- */
-
- /*
- 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();
-
- 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 (UGL_BOOL windMLMode);
-
- void uglpoint (void)
- {
- taskSpawn ("tPoint", 210, VX_FP_TASK, 100000,
- (FUNCPTR)windMLPoint, UGL_FALSE,1,2,3,4,5,6,7,8,9);
- }
-
- void windMLPoint (UGL_BOOL windMLMode)
- {
- 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)
- {
- if (windMLMode)
- umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE
- | UGL_MESA_WINDML_EXCLUSIVE, NULL);
- else
- umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL);
- }
- else
- {
- if (windMLMode)
- umc = uglMesaCreateNewContext(UGL_MESA_SINGLE
- | UGL_MESA_WINDML_EXCLUSIVE, 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;
- }
|