// Name : OpenGL Color Cube
// Author : Terrence Ma
// Email : terrence@terrence.com
// Web : http://www.terrence.com
// Date : 10/25/2001
// Modified : Tutorial sample from Mesa3d.org (http://www.mesa3d.org)
/*
* Copyright (c) 1993-1997, 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(R) is a registered trademark of Silicon Graphics, Inc.
*/
/*
* aapoly.c
* This program draws filled polygons with antialiased
* edges. The special GL_SRC_ALPHA_SATURATE blending
* function is used.
* Pressing the 't' key turns the antialiasing on and off.
*/
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
GLboolean polySmooth = GL_TRUE;
static void init(void)
{
glCullFace (GL_BACK);
glEnable (GL_CULL_FACE);
glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
glClearColor (0.0, 0.0, 0.0, 0.0);
}
#define NFACE 6
#define NVERT 8
void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1,
GLdouble z0, GLdouble z1)
{
static GLfloat v[8][3];
static GLfloat c[8][4] = {
{0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 1.0},
{0.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0},
{0.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 1.0, 1.0},
{0.0, 1.0, 1.0, 1.0}, {1.0, 1.0, 1.0, 1.0}
};
/* indices of front, top, left, bottom, right, back faces */
static GLubyte indices[NFACE][4] = {
{4, 5, 6, 7}, {2, 3, 7, 6}, {0, 4, 7, 3},
{0, 1, 5, 4}, {1, 5, 6, 2}, {0, 3, 2, 1}
};
v[0][0] = v[3][0] = v[4][0] = v[7][0] = x0;
v[1][0] = v[2][0] = v[5][0] = v[6][0] = x1;
v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
v[0][2] = v[1][2] = v[2][2] = v[3][2] = z0;
v[4][2] = v[5][2] = v[6][2] = v[7][2] = z1;
#ifdef GL_VERSION_1_1
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_COLOR_ARRAY);
glVertexPointer (3, GL_FLOAT, 0, v);
glColorPointer (4, GL_FLOAT, 0, c);
glDrawElements (GL_QUADS, NFACE*4, GL_UNSIGNED_BYTE, indices);
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_COLOR_ARRAY);
#else
printf ("If this is GL Version 1.0, ");
printf ("vertex arrays are not supported.\n");
exit(1);
#endif
}
/* Note: polygons must be drawn from front to back
* for proper blending.
*/
void display(void)
{
if (polySmooth) {
glClear (GL_COLOR_BUFFER_BIT);
glEnable (GL_BLEND);
glEnable (GL_POLYGON_SMOOTH);
glDisable (GL_DEPTH_TEST);
}
else {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable (GL_BLEND);
glDisable (GL_POLYGON_SMOOTH);
glEnable (GL_DEPTH_TEST);
}
glPushMatrix ();
glTranslatef (0.0, 0.0, -8.0);
glRotatef (30.0, 1.0, 0.0, 0.0);
glRotatef (60.0, 0.0, 1.0, 0.0);
drawCube(-0.8, 0.8, -0.8, 0.8, -0.8, 0.8);
glPopMatrix ();
glFlush ();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 't':
case 'T':
polySmooth = !polySmooth;
glutPostRedisplay();
break;
case 27:
exit(0); /* Escape key */
break;
default:
break;
}
}
/* Main Loop
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB
| GLUT_ALPHA | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("OpenGL Color Cube");
init ();
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutDisplayFunc (display);
glutMainLoop();
return 0;
}
SGI OpenGL Color Cube
时间: 2024-10-03 02:39:10
SGI OpenGL Color Cube的相关文章
SGI OpenGL Teapot
// Name : OpenGL Teapot// Author : Terrence Ma// Email : terrence@terrence.com// Web : http://www.terrence.com// Date : 10/25/2001// Modified : Tutorial sample from Mesa3d.org (http://www.mesa3d.org)/* * Copyright (c) 1993-1997, S
1.12. 补充信息 - Further Information
1.12. 补充信息 - Further Information The Web site http://opengl.org has the latest information for the OpenGL community, forums for developers, and links to a variety of demos and technical information. OpenGL developers should bookmark this site and vis
OpenGL入门介绍
1.OpenGL简介 OpenGL是近几年发展起来的一个性能卓越的三维图形标准,它是在SGI等多家世界闻名的计算机公司的倡导下,以SGI的GL三维图形库为基础制定的一个通用共享的开放式三维图形标准.目前,包括Microsoft.SGI.IBM.DEC.SUN.HP等大公司都采用了OpenGL做为三维图形标准,许多软件厂商也纷纷以OpenGL为基础开发出自己的产品,其中比较著名的产品包括动画制作软件Soft Image和3D Studio MAX.仿真软件Open Inventor.VR软件Wor
OpenGL ES From the Ground Up, Part 4: Let There Be Light!
FRIDAY, MAY 1, 2009 OpenGL ES From the Ground Up, Part 4: Let There Be Light! Continuing on with OpenGL ES for the iPhone, let's talk about light. So far, we haven't done anything with light. Fortunately, OpenGL still lets us see what's going on if w
android 使用 opengl 2.0 显示一张静态背景图片,效果显示出来的很奇怪
问题描述 android 使用 opengl 2.0 显示一张静态背景图片,效果显示出来的很奇怪 背景原图是: 显示的效果却是: 我不知道我的代码错在哪了.请有OpenGL开发经验的兄弟帮忙下.我的代码如下: public class BackgroundGLRnder implements GLSurfaceView.Renderer { // Our matrices private final float[] mtrxProjection = new float[16]; private
WebGL and OpenGL Differences - 非2的次幂纹理的那些讲究儿
WebGL and OpenGL Differences WebGL is based on the OpenGL ES 2.0 specification, and retains the semantics of OpenGL ES in order to maximize portability to mobile devices. There are some significant differences in behavior of similar APIs between Open
第二章 你好三角形:一个OpenGL ES 2.0例子
介绍基本概念的OpenGL ES 2.0,我们首先从一个简单的例子.在这一章里,我们将展示什么是需要创建一个OpenGL ES 2.0一个三角形的项目..我们要编写的程序是最基本的例子,一个OpenGL ES 2.0应用程序,绘制几何.有数量的概念,我们将介绍在本章: 1.创建一个屏幕渲染表面与EGL. 2.加载片段着色器和定点. 3.创建程序的对象,附着顶点和片段着色器,连接程序对象. 4.设置窗口. 5.清除颜色缓冲. 6.渲染一个简单的例子. 7.使内容的颜色缓冲可见在EGL窗口表面. 事
OpenGl第三章后续,纹理,绘制图片,文字
OpenGl第三章后续,纹理,绘制图片,文字,直接 // 创建文理gl.glEnable(GL10.GL_TEXTURE_2D);texturesBuffer = IntBuffer.allocate(1);gl.glGenTextures(1, texturesBuffer);gl.glBindTexture(GL10.GL_TEXTURE_2D, texturesBuffer.get(0)); // 设置文理的参数gl.glTexParameterx(GL10.GL_TEXTURE_2D,
64位系统运行nehe opengl
问题描述 64位系统运行nehe opengl 我按照网上下载的nehe sdk进行配置以后,运行以后不出现opengl的窗口. 但使用网上另外一段opengl代码就运行成功了,不知道是不是因为64位系统的问题,用的是systemwow64文件夹存放dll. 解决方案 #include "opengl.h" #include "view.h" using namespace NeHe; // the view class static View view; stat