资源简介
SDLPro10
代码片段和文件信息
#include “cgl.h“
CGL::CGL()
{
//ctor
}
CGL::CGL(int _width int _height)
{
this->width = _width;
this->height = _height;
}
CGL::~CGL()
{
//dtor
}
bool CGL::initGL()
{
float ratio = width / height;
// Our shading model--Gouraud (smooth).
glShadeModel( GL_SMOOTH );
// Set the clear color.
glClearColor( 0 0 0 0 );
// Setup our viewport.
glViewport( 0 0 width height );
glEnable(GL_DEPTH_TEST);
//Change to the projection matrix and set our viewing volume.
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 60.0 ratio 1.0 100.0 );
GLfloat light_position[] = {13.0 13.0 13.0 0.0};
GLfloat white_light[] = {1.0 0.0 0.0 1.0};
GLfloat lmodel_ambient[] = {0.1 0.1 0.1 1.0};
glLightfv(GL_LIGHT0GL_POSITIONlight_position);
glLightfv(GL_LIGHT0GL_DIFFUSEwhite_light);
glLightfv(GL_LIGHT0GL_SPECULARwhite_light);
GLfloat mat_specular[] = {1.0 1.0 1.0 1.0};
GLfloat mat_shininess[] = {50.0};
glMaterialfv(GL_FRONTGL_SPECULARmat_specular);
glMaterialfv(GL_FRONTGL_SHININESSmat_shininess);
glLightModelfv(GL_LIGHT_MODEL_AMBIENTlmodel_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
Util util;
//Read .obj file and store the infos
bool res = util.loadOBJ(“monkey.obj“ vertices uvs normals);
return( true );
}
bool CGL::resizeGL(int widthint height)
{
if ( height == 0 )
{
height = 1;
}
//Reset View
glViewport( 0 0 (GLint)width (GLint)height );
//Choose the Matrix mode
glMatrixMode( GL_PROJECTION );
//reset projection
glLoadIdentity();
//set perspection
gluPerspective( 45.0 (GLfloat)width/(GLfloat)height 0.1 100.0 );
//choose Matrix mode
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
bool CGL::renderGL()
{
/* These are to calculate our fps */
static GLint T0 = 0;
static GLint frames = 0;
// Clear the color and depth buffers.
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// We don‘t want to modify the projection matrix. */
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );
// glTranslatef( 0.0f 0.0f -6.0f );
// Move down the z-axis.
glTranslatef( 0.0 0.0 -5.0 );
glRotatef(1201.01.00.0);
int nodesSize = vertices.size();
int i;
glBegin(GL_TRIANGLES);
for(i = 0; i {
glNormal3f(normals[i].x normals[i].y normals[i].z);
glVertex3f( vertices[i].x vertices[i].y vertices[i].z);
}
glEnd();
SDL_GL_SwapBuffers( );
/* Gather our frames per second */
frames++;
{
GLint t = SDL_GetTicks();
if (t - T0 >= 5000) {
GLfloat seconds = (t - T0) / 1000.0;
GLfloat fps = frames / seconds;
printf(“%d frames in %g seconds = %g FPS\n“ frames seconds fps);
T0 = t;
frames = 0;
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 452 2013-08-01 14:59 util.h
文件 4152 2013-08-02 02:26 util.cpp
文件 843 2013-08-02 02:44 SDLTest.layout
文件 797 2013-08-02 02:59 SDLTest.depend
文件 1373 2013-08-01 15:30 SDLTest.cbp
文件 58002 2013-08-01 06:59 monkey.obj
文件 591 2013-08-02 02:51 main.cpp
文件 758 2013-08-02 01:45 csdl.h
文件 3044 2013-08-02 01:45 csdl.cpp
文件 572 2013-08-02 02:15 cgl.h
文件 2922 2013-08-02 02:57 cgl.cpp
文件 38023 2013-08-01 13:17 boy.obj
文件 20052 2013-08-02 02:51 obj\Debug\main.o
文件 77296 2013-08-02 02:58 obj\Debug\cgl.o
文件 21460 2013-08-01 14:17 obj\Debug\sdl.o
文件 35016 2013-08-02 02:19 obj\Debug\csdl.o
文件 204644 2013-08-02 02:27 obj\Debug\util.o
文件 203914 2013-08-02 02:58 bin\Debug\SDLTest
目录 0 2013-08-02 02:58 obj\Debug\
目录 0 2013-08-01 13:50 obj\
目录 0 2013-08-02 02:58 bin\Debug\
目录 0 2013-08-01 13:50 bin\
- 上一篇:批量根据经纬度计算距离
- 下一篇:基于Qt的图像采集系统
评论
共有 条评论