Лекции OpenFrameworks: рисование 3D-поверхностей

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

OpenFrameworks

3D

:
www.uralvision.blogspot.com


perevalovds@gmail.com

/ 2012

setup():
-
- ( )
()
1. update():
- , .
2. draw():
- 4- 3- .
- , .

(
).


glShadeModel (GL_SMOOTH);
// . GL_FLAT
glEnable (GL_COLOR_MATERIAL); //
glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
//,
GLfloat ambientLight[] = {0.2f, 0.2f, 0.2f};
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambientLight );

//

GLfloat specref[] = {0.5, 0.5, 0.5, 1.0};


//
glMaterialfv( GL_FRONT, GL_SPECULAR, specref ); //
glMateriali(GL_FRONT, GL_SHININESS, 128); // (0..128)
// 0 ( 8 )
GLfloat light0[] = {-200, 800, 200.0, 1.0 };
//
glLightfv (GL_LIGHT0, GL_POSITION, light0);
GLfloat diffuse0[] = {0.8, 0.8, 0.8, 0.8};
//
glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse0);
GLfloat specular0[] = {0.3, 0.3, 0.3, 0.3};
glLightfv (GL_LIGHT0, GL_SPECULAR, specular0);
glEnable (GL_LIGHT0);
glEnable (GL_LIGHTING);

//

// 0-
//

:
http://compgraphics.info/OpenGL/lighting/materials.php
http://www.opengl.org/sdk/docs/man/xhtml/glMaterial.xml


glEnable (GL_DEPTH_TEST); // Z-
//

// ,
// .
//, , http://www.gamedev.ru/code/articles/openglcamera


1
- , .
, , w x h, ,
vector<ofPoint> surf( w * h ) - ,
vector<ofPoint> tex( w * h ) - ,
vector<ofPoint> norm( w * h ) - ,
ofImage image;
image.getTextureReference().bind();
glBegin( GL_QUADS );
for (int yi=0; yi<h-1; yi++) {
for (int xi=0; xi<w-1; xi++) {
//
int index[4];
index[0] = xi + w * yi;
index[1] = xi+1 + w * yi;
index[2] = xi+1 + w * (yi+1);
index[3] = xi + w * (yi+1);
//
for (int i=0; i<4; i++) {
glNormal3f( norm[index[i]].x, norm[index[i]].y, norm[index[i]].z );
glTexCoord2f( tex[index[i]].x, tex[index[i]].y );
glVertex3f( surf[index[i]].x, _surf[index[i]].y, _surf[index[i]].z );
}
}
}
glEnd();
image.getTextureReference().unbind();


2
- ,
vector<float>,
- surfGL, texGL, normGL.
image.getTextureReference().bind();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &surfGL[0]);
glTexCoordPointer( 2, GL_FLOAT, 0, &texGL[0] );
glNormalPointer( GL_FLOAT, 0, &normGL[0] );
int n = (w-1) * (h-1);
glDrawArrays(GL_QUADS, 0, n * 4);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
image.getTextureReference().unbind();


, ,
.
draw():
ofPushMatrix();
// ,
ofTranslate( 1024 / 2, 768/2, 0 );
// .
// 1024x768, (0,0,0),
//
ofScale( 0.5, 0.5, 0.5 );
ofRotateX( 25 );

//
// , -

// ( )
//...
ofPopMatrix();

//

,
. - .

You might also like