PageRenderTime 282ms CodeModel.GetById 91ms app.highlight 7ms RepoModel.GetById 123ms app.codeStats 0ms

/opengles/redbook/model.c

http://ftk.googlecode.com/
C | 123 lines | 68 code | 12 blank | 43 comment | 2 complexity | 137765fee6bd52fc853c7fde4570e182 MD5 | raw file
  1/*
  2 * License Applicability. Except to the extent portions of this file are
  3 * made subject to an alternative license as permitted in the SGI Free
  4 * Software License B, Version 1.1 (the "License"), the contents of this
  5 * file are subject only to the provisions of the License. You may not use
  6 * this file except in compliance with the License. You may obtain a copy
  7 * of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
  8 * Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
  9 * 
 10 * http://oss.sgi.com/projects/FreeB
 11 * 
 12 * Note that, as provided in the License, the Software is distributed on an
 13 * "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
 14 * DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
 15 * CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
 16 * PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
 17 * 
 18 * Original Code. The Original Code is: OpenGL Sample Implementation,
 19 * Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
 20 * Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
 21 * Copyright in any portions created by third parties is as indicated
 22 * elsewhere herein. All Rights Reserved.
 23 * 
 24 * Additional Notice Provisions: The application programming interfaces
 25 * established by SGI in conjunction with the Original Code are The
 26 * OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
 27 * April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
 28 * 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
 29 * Window System(R) (Version 1.3), released October 19, 1998. This software
 30 * was created using the OpenGL(R) version 1.2.1 Sample Implementation
 31 * published by SGI, but has not been independently verified as being
 32 * compliant with the OpenGL(R) version 1.2.1 Specification.
 33 *
 34 */
 35
 36/*
 37 *  model.c
 38 *  This program demonstrates modeling transformations
 39 */
 40#include <stdlib.h>
 41#include "ug.h"
 42
 43void init(void) 
 44{
 45   static const GLfloat v[6] = { 0.0, 25.0, 25.0, -25.0, -25.0, -25.0 };
 46   glClearColor (0.0, 0.0, 0.0, 0.0);
 47   glShadeModel (GL_FLAT);
 48   glVertexPointer(2, GL_FLOAT, 0, v);
 49   glEnableClientState (GL_VERTEX_ARRAY);
 50}
 51
 52void draw_triangle(void)
 53{
 54   glDrawArrays(GL_LINE_LOOP, 0, 3);
 55}
 56
 57void display(UGWindow uwin)
 58{
 59   glClear (GL_COLOR_BUFFER_BIT);
 60   glColor4f (1.0, 1.0, 1.0, 1.0);
 61
 62   glLoadIdentity ();
 63   glColor4f (1.0, 1.0, 1.0, 1.0);
 64   draw_triangle ();
 65
 66   /*glEnable (GL_LINE_STIPPLE);*/
 67   /*glLineStipple (1, 0xF0F0);*/
 68   glColor4f(1.0f, 0.f, 0.f, 1.f);
 69   glLoadIdentity ();
 70   glTranslatef (-20.0, 0.0, 0.0);
 71   draw_triangle ();
 72
 73   /*glLineStipple (1, 0xF00F);*/
 74   glColor4f(0.0f, 1.f, 0.f, 1.f);
 75   glLoadIdentity ();
 76   glScalef (1.5, 0.5, 1.0);
 77   draw_triangle ();
 78
 79   /*glLineStipple (1, 0x8888);*/
 80   glColor4f(0.0f, 0.f, 1.f, 1.f);
 81   glLoadIdentity ();
 82   glRotatef (90.0, 0.0, 0.0, 1.0);
 83   draw_triangle ();
 84   /*glDisable (GL_LINE_STIPPLE);*/
 85
 86   glFlush ();
 87   ugSwapBuffers(uwin);
 88}
 89
 90void reshape (UGWindow uwin, int w, int h)
 91{
 92   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
 93   glMatrixMode (GL_PROJECTION);
 94   glLoadIdentity ();
 95   if (w <= h)
 96      glOrthof(-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
 97         50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
 98   else
 99      glOrthof(-50.0*(GLfloat)w/(GLfloat)h,
100         50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
101   glMatrixMode(GL_MODELVIEW);
102}
103
104void keyboard(UGWindow uwin, int key, int x, int y)
105{
106   switch (key) {
107      case 27:
108         exit(0);
109         break;
110   }
111}
112
113int main(int argc, char** argv)
114{
115   UGCtx ug = ugInit();
116   UGWindow uwin = ugCreateWindow (ug, "", argv[0], 500, 500, 100, 100);
117   init ();
118   ugDisplayFunc(uwin, display); 
119   ugReshapeFunc(uwin, reshape);
120   ugKeyboardFunc(uwin, keyboard);
121   ugMainLoop(ug);
122   return 0;
123}