/*! \file shapes.c
\ingroup demos
This program is a test harness for the various shapes
in OpenGLUT. It may also be useful to see which
parameters control what behavior in the OpenGLUT
objects.
Spinning wireframe and solid-shaded shapes are
displayed. Some parameters can be adjusted.
Keys:
- <tt>Esc </tt> Quit
- <tt>q Q </tt> Quit
- <tt>i I </tt> Show info
- <tt>p P </tt> Toggle perspective or orthographic projection
- <tt>r R </tt> Toggle fixed or animated rotation around model X-axis
- <tt>s S </tt> Toggle toggle fixed function or shader render path
- <tt>n N </tt> Toggle visualization of object's normal vectors
- <tt>= + </tt> Increase \a slices
- <tt>- _ </tt> Decreate \a slices
- <tt>, < </tt> Decreate \a stacks
- <tt>. > </tt> Increase \a stacks
- <tt>9 ( </tt> Decreate \a depth (Sierpinski Sponge)
- <tt>0 ) </tt> Increase \a depth (Sierpinski Sponge)
- <tt>up </tt> Increase "outer radius"
- <tt>down </tt> Decrease "outer radius"
- <tt>left </tt> Decrease "inner radius"
- <tt>right</tt> Increase "inner radius"
- <tt>PgUp </tt> Next shape-drawing function
- <tt>PgDn </tt> Prev shape-drawing function
\author Written by Nigel Stewart November 2003
\author Portions Copyright (C) 2004, the OpenGLUT project contributors. <br>
OpenGLUT branched from freeglut in February, 2004.
\image html openglut_shapes.png OpenGLUT Geometric Shapes Demonstration
\include demos/shapes/shapes.c
*/
#include <GL/freeglut.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include "glmatrix.h"
#ifdef _MSC_VER
/* DUMP MEMORY LEAKS */
#include <crtdbg.h>
#endif
/* report GL errors, if any, to stderr */
void checkError(const char *functionName)
{
GLenum error;
while (( error = glGetError() ) != GL_NO_ERROR) {
fprintf (stderr, "GL error 0x%X detected in %s\n", error, functionName);
}
}
/*
* OpenGL 2+ shader mode needs some function and macro definitions,
* avoiding a dependency on additional libraries like GLEW or the
* GL/glext.h header
*/
#ifndef GL_FRAGMENT_SHADER
#define GL_FRAGMENT_SHADER 0x8B30
#endif
#ifndef GL_VERTEX_SHADER
#define GL_VERTEX_SHADER 0x8B31
#endif
#ifndef GL_COMPILE_STATUS
#define GL_COMPILE_STATUS 0x8B81
#endif
#ifndef GL_LINK_STATUS
#define GL_LINK_STATUS 0x8B82
#endif
#ifndef GL_INFO_LOG_LENGTH
#define GL_INFO_LOG_LENGTH 0x8B84
#endif
typedef ptrdiff_t ourGLsizeiptr;
typedef char ourGLchar;
#ifndef APIENTRY
#define APIENTRY
#endif
#ifndef GL_VERSION_2_0
typedef GLuint (APIENTRY *PFNGLCREATESHADERPROC) (GLenum type);
typedef void (APIENTRY *PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const ourGLchar **string, const GLint *length);
typedef void (APIENTRY *PFNGLCOMPILESHADERPROC) (GLuint shader);
typedef GLuint (APIENTRY *PFNGLCREATEPROGRAMPROC) (void);
typedef void (APIENTRY *PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
typedef void (APIENTRY *PFNGLLINKPROGRAMPROC) (GLuint program);
typedef void (APIENTRY *PFNGLUSEPROGRAMPROC) (GLuint program);
typedef void (APIENTRY *PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
typedef void (APIENTRY *PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, ourGLchar *infoLog);
typedef void (APIENTRY *PFNGLGETPROGRAMIVPROC) (GLenum target, GLenum pname, GLint *params);
typedef void (APIENTRY *PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, ourGLchar *infoLog);
typedef GLint (APIENTRY *PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const ourGLchar *name);
typedef GLint (APIENTRY *PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const ourGLchar *name);
typedef void (APIENTRY *PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
typedef void (APIENTRY *PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
#endif
PFNGLCREATESHADERPROC gl_CreateShader;
PFNGLSHADERSOURCEPROC gl_ShaderSource;
PFNGLCOMPILESHADERPROC gl_CompileShader;
PFNGLCREATEPROGRAMPROC gl_CreateProgram;
PFNGLATTACHSHADERPROC gl_AttachShader;
PFNGLLINKPROGRAMPROC gl_LinkProgram;
PFNGLUSEPROGRAMPROC gl_UseProgram;
PFNGLGETSHADERIVPROC gl_GetShaderiv;
PFNGLGETSHADERINFOLOGPROC gl_GetShaderInfoLog;
PFNGLGETPROGRAMIVPROC gl_GetProgramiv;
PFNGLGETPROGRAMINFOLOGPROC gl_GetProgramInfoLog;
PFNGLGETATTRIBLOCATIONPROC gl_GetAttribLocation;
PFNGLGETUNIFORMLOCATIONPROC gl_GetUniformLocation;
PFNGLUNIFORMMATRIX4FVPROC gl_UniformMatrix4fv;
PFNGLUNIFORMMATRIX3FVPROC gl_UniformMatrix3fv;
void initExtensionEntries(void)
{
gl_CreateShader = (PFNGLCREATESHADERPROC) glutGetProcAddress ("glCreateShader");
gl_ShaderSource = (PFNGLSHADERSOURCEPROC) glutGetProcAddress ("glShaderSource");
gl_CompileShader = (PFNGLCOMPILESHADERPROC) glutGetProcAddress ("glCompileShader");
gl_CreateProgram = (PFNGLCREATEPROGRAMPROC) glutGetProcAddress ("glCreateProgram");
gl_AttachShader = (PFNGLATTACHSHADERPROC) glutGetProcAddress ("glAttachShader");
gl_LinkProgram = (PFNGLLINKPROGRAMPROC) glutGetProcAddress ("glLinkProgram");
gl_UseProgram = (PFNGLUSEPROGRAMPROC) glutGetProcAddress ("glUseProgram");
gl_GetShaderiv = (PFNGLGETSHADERIVPROC) glutGetProcAddress ("glGetShaderiv");
gl_GetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) glutGetProcAddress ("glGetShaderInfoLog");
gl_GetProgramiv = (PFNGLGETPROGRAMIVPROC) glutGetProcAddress ("glGetProgramiv");
gl_GetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) glutGetProcAddress ("glGetProgramInfoLog");
gl_GetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC) glutGetProcAddress ("glGetAttribLocation");
gl_GetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) glutGetProcAddress ("glGetUniformLocation");
gl_UniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) glutGetProcAddress ("glUniformMatrix4fv");
gl_UniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC) glutGetProcAddress ("glUniformMatrix3fv");
if (!gl_CreateShader || !gl_ShaderSource || !gl_CompileShader || !gl_CreateProgram || !gl_AttachShader || !gl_LinkProgram || !gl_UseProgram || !gl_GetShaderiv || !gl_GetShaderInfoLog || !gl_GetProgramiv || !gl_GetProgramInfoLog || !gl_GetAttribLocation || !gl_GetUniformLocation || !gl_UniformMatrix4fv || !gl_UniformMatrix3fv)
{
fprintf (stderr, "glCreateShader, glShaderSource, glCompileShader, glCreateProgram, glAttachShader, glLinkProgram, glUseProgram, glGetShaderiv, glGetShaderInfoLog, glGetProgramiv, glGetProgramInfoLog, glGetAttribLocation, glGetUniformLocation, glUniformMatrix4fv or gl_UniformMatrix3fv not found");
exit(1);
}
}
const ourGLchar *vertexShaderSource[] = {
"/**",
" * From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/GLSL_Programming/GLUT/Smooth_Specular_Highlights",
" * This file is in the public domain.",
" * Contributors: Sylvain Beucler",
" */",
"attribute vec3 fg_coord;",
"attribute vec3 fg_normal;",
"varying vec4 position; /* position of the vertex (and fragment) in world space */",
"varying vec3 varyingNormalDirection; /* surface normal vector in world space */",
"uniform mat4 m, p; /* don't need v, as always identity in our demo */",
"uniform mat3 m_3x3_inv_transp;",
" ",
"void main()",
"{",
" vec4 fg_coord4 = vec4(fg_coord, 1.0);",
" position = m * fg_coord4;",
" varyingNormalDirection = normalize(m_3x3_inv_transp * fg_normal);",
" ",
" mat4 mvp = p*m; /* normally p*v*m */",
" gl_Position = mvp * fg_coord4;",
"}"
};
const ourGLchar *fragmentShaderSource[] = {
"/**",
" * From the OpenGL Programming wikibook: http://en.wikibooks.org/wiki/GLSL_Prog
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
qt 轻量级GCC编译器IDE (1525个子文件)
ball.bmp 630B
ballmask.bmp 190B
changelog 2KB
compat 3B
control 724B
copyright 3KB
mainwindow.cpp 280KB
ASFormatter.cpp 232KB
SynEdit.cpp 221KB
cppparser.cpp 160KB
editor.cpp 157KB
settings.cpp 142KB
astyle_main.cpp 126KB
ASBeautifier.cpp 108KB
project.cpp 89KB
debugger.cpp 74KB
ASLocalizer.cpp 64KB
cpppreprocessor.cpp 55KB
TextPainter.cpp 46KB
cpp.cpp 43KB
glsl.cpp 43KB
codecompletionpopup.cpp 42KB
darkfusionstyle.cpp 41KB
qconsole.cpp 36KB
utils.cpp 34KB
TextBuffer.cpp 30KB
ASResource.cpp 27KB
compiler.cpp 24KB
iconsmanager.cpp 24KB
colorscheme.cpp 23KB
parserutils.cpp 22KB
projectcompiler.cpp 22KB
gitmanager.cpp 19KB
ASEnhancer.cpp 18KB
cpptokenizer.cpp 18KB
formattergeneralwidget.cpp 18KB
searchdialog.cpp 18KB
editorcolorschemewidget.cpp 17KB
compilermanager.cpp 17KB
platform.cpp 16KB
searchresultview.cpp 15KB
classbrowser.cpp 14KB
ojproblemsetmodel.cpp 14KB
main.cpp 14KB
compilersetoptionwidget.cpp 13KB
gdbmiresultparser.cpp 12KB
cpprefacter.cpp 12KB
editorlist.cpp 12KB
asm.cpp 12KB
compilerinfo.cpp 12KB
settingsdialog.cpp 11KB
thememanager.cpp 11KB
KeyStrokes.cpp 11KB
synexporter.cpp 11KB
headercompletionpopup.cpp 10KB
environmentfileassociationwidget.cpp 10KB
codesnippetsmanager.cpp 9KB
projecttemplate.cpp 9KB
executablerunner.cpp 9KB
projectfileswidget.cpp 8KB
newprojectdialog.cpp 8KB
synhtmlexporter.cpp 8KB
bookmarkmodel.cpp 8KB
main.windows.cpp 7KB
compilerautolinkwidget.cpp 7KB
ojproblemcasesrunner.cpp 7KB
toolsgeneralwidget.cpp 7KB
environmentshortcutwidget.cpp 7KB
settingswidget.cpp 7KB
HighlighterManager.cpp 7KB
cpudialog.cpp 7KB
MiscClasses.cpp 6KB
issuestable.cpp 6KB
editorgeneralwidget.cpp 6KB
main.unix.cpp 6KB
functiontooltipwidget.cpp 6KB
customfileiconprovider.cpp 6KB
MiscProcs.cpp 6KB
projectgeneralwidget.cpp 6KB
projectcompilerwidget.cpp 5KB
gitremotedialog.cpp 5KB
synrtfexporter.cpp 5KB
linenumbertexteditor.cpp 5KB
base.cpp 5KB
compileargumentswidget.cpp 5KB
filepropertiesdialog.cpp 5KB
statementmodel.cpp 5KB
projectversioninfowidget.cpp 5KB
todoparser.cpp 5KB
editorfontwidget.cpp 5KB
autolinkmanager.cpp 5KB
environmentappearencewidget.cpp 5KB
editormiscwidget.cpp 5KB
toolsmanager.cpp 4KB
shortcutmanager.cpp 4KB
debuggeneralwidget.cpp 4KB
editorcodecompletionwidget.cpp 4KB
systemconsts.cpp 4KB
editorclipboardwidget.cpp 4KB
gitlogdialog.cpp 4KB
共 1525 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
hkSDK
- 粉丝: 11
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0