计算机图形学opengl+shader几个


里面有几个计算机图形学的基础实例都是根据opengl+shader一起实现的。实例有:三角形,镂空图形,koch曲线课实现多边形多递归,还有colorcube
资源截图
代码片段和文件信息
//
// Display a color cube
//
// Colors are assigned to each vertex and then the rasterizer interpolates
//   those colors across the triangles.  We us an orthographic projection
//   as the default projetion.

#include “Angel.h“

typedef Angel::vec4  color4;
typedef Angel::vec4  point4;

const int NumVertices = 36; //(6 faces)(2 triangles/face)(3 vertices/triangle)

point4 points[NumVertices];
color4 colors[NumVertices];

// Vertices of a unit cube centered at origin sides aligned with axes
point4 vertices[8] = {
    point4( -0.5 -0.5  0.5 1.0 )
    point4( -0.5  0.5  0.5 1.0 )
    point4(  0.5  0.5  0.5 1.0 )
    point4(  0.5 -0.5  0.5 1.0 )
    point4( -0.5 -0.5 -0.5 1.0 )
    point4( -0.5  0.5 -0.5 1.0 )
    point4(  0.5  0.5 -0.5 1.0 )
    point4(  0.5 -0.5 -0.5 1.0 )
};

// RGBA olors
color4 vertex_colors[8] = {
    color4( 0.0 0.0 0.0 1.0 )  // black
    color4( 1.0 0.0 0.0 1.0 )  // red
    color4( 1.0 1.0 0.0 1.0 )  // yellow
    color4( 0.0 1.0 0.0 1.0 )  // green
    color4( 0.0 0.0 1.0 1.0 )  // blue
    color4( 1.0 0.0 1.0 1.0 )  // magenta
    color4( 1.0 1.0 1.0 1.0 )  // white
    color4( 0.0 1.0 1.0 1.0 )   // cyan
};

// Array of rotation angles (in degrees) for each coordinate axis
enum { Xaxis = 0 Yaxis = 1 Zaxis = 2 NumAxes = 3 };
int      Axis = Xaxis;
GLfloat  theta[NumAxes] = { 0.0 0.0 0.0 };

GLint matrix_loc;  // The location of the “rotation“ shader uniform variable


//----------------------------------------------------------------------------

// quad generates two triangles for each face and assigns colors
//    to the vertices
int Index = 0;
void
quad( int a int b int c int d )
{
    colors[Index] = vertex_colors[a]; points[Index] = vertices[a]; Index++;
    colors[Index] = vertex_colors[b]; points[Index] = vertices[b]; Index++;
    colors[Index] = vertex_colors[c]; points[Index] = vertices[c]; Index++;
    colors[Index] = vertex_colors[a]; points[Index] = vertices[a]; Index++;
    colors[Index] = vertex_colors[c]; points[Index] = vertices[c]; Index++;
    colors[Index] = vertex_colors[d]; points[Index] = vertices[d]; Index++;
}

//----------------------------------------------------------------------------

// generate 12 triangles: 36 vertices and 36 colors
void
colorcube()
{
    quad( 1 0 3 2 );
    quad( 2 3 7 6 );
    quad( 3 0 4 7 );
    quad( 6 5 1 2 );
    quad( 4 5 6 7 );
    quad( 5 4 0 1 );
}

//----------------------------------------------------------------------------

// OpenGL initialization
void
init()
{
    colorcube();

    // Create a vertex array object
    GLuint vao;
    glGenVertexArrays( 1 &vao );
    glBindVertexArray( vao );

    // Create and initialize a buffer object
    GLuint buffer;
    glGenBuffers( 1 &buffer );
    glBindBuffer( GL_ARRAY_BUFFER buffer );
    glBufferData( GL_ARRAY_BUFFER sizeof(

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2079  2013-04-17 11:23  hellohello.cpp

     文件     429568  2013-04-17 18:00  hellohello.exe

     文件         90  2013-03-25 00:15  hellohello.fs

     文件       9265  2013-04-07 17:51  hellohello.vcxproj

     文件        143  2013-03-24 21:12  hellohello.vcxproj.user

     文件         79  2010-11-07 19:23  hellohello.vs

     文件       3400  2013-04-17 16:46  kochkoch.cpp

     文件     438784  2013-04-17 18:00  kochkoch.exe

     文件         90  2013-04-07 16:57  kochkoch.fs

     文件       9258  2013-04-07 16:59  kochkoch.vcxproj

     文件        143  2013-03-24 23:39  kochkoch.vcxproj.user

     文件         79  2010-11-07 19:23  kochkoch.vs

     文件         94  2013-04-07 17:51  single_doubleDebugsingle_double.log

     文件       2643  2013-03-31 23:01  single_doublesingle_double.cpp

     文件     218112  2013-04-17 18:00  single_doublesingle_double.exe

     文件       9150  2013-04-07 17:51  single_doublesingle_double.vcxproj

     文件        143  2013-03-31 23:00  single_doublesingle_double.vcxproj.user

     文件         94  2013-04-07 17:51  single_doubleTemplatesingle_double.log

     文件        178  2010-03-16 10:59  clean.cmd

     文件       5480  2013-04-14 22:06  my_example.sln

     文件       5800  2013-04-17 17:58  colorcubecolorcube.cpp

     文件     433152  2013-04-17 18:00  colorcubecolorcube.exe

     文件         84  2010-11-10 14:14  colorcubecolorcube.fs

     文件       9293  2013-04-14 21:54  colorcubecolorcube.vcxproj

     文件        143  2013-04-14 21:55  colorcubecolorcube.vcxproj.user

     文件        182  2013-04-17 17:46  colorcubecolorcube.vs

     文件       2176  2013-03-24 19:18  commonincludeAngel.h

     文件       1290  2010-11-07 19:23  commonincludeCheckError.h

     文件        681  2003-10-21 19:41  commonincludeGLfreeglut.h

     文件       8797  2011-09-05 03:38  commonincludeGLfreeglut_ext.h

............此处省略73个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)