VolumeRendering
QGL Example
← QGL Class Concept | ● | OpenGL Texturing →
A simple animated rotating green triangle with OpenGL:
void QGLWindow::paintGL()
{
// clear frame buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// setup perspective matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,(float)width()/height(),0.1,10.0);
// setup model-view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// define local rotated coordinate system
static double angle=0.0; // rotation angle in degrees
static const double omega=180.0; // rotation speed in degrees/s
glTranslated(0.0,0.0,-2.0);
glRotated(angle,0.0,1.0,0.0);
// render triangles
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.75f,0.0f);
glVertex3d(-0.5,-0.5,0.0);
glVertex3d(0.5,-0.5,0.0);
glVertex3d(0.0,0.5,0.0);
glEnd();
// angle delta equals time delta times omega
double dt=1.0/fps;
angle+=dt*omega;
}
{
// clear frame buffer
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// setup perspective matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0,(float)width()/height(),0.1,10.0);
// setup model-view matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// define local rotated coordinate system
static double angle=0.0; // rotation angle in degrees
static const double omega=180.0; // rotation speed in degrees/s
glTranslated(0.0,0.0,-2.0);
glRotated(angle,0.0,1.0,0.0);
// render triangles
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.75f,0.0f);
glVertex3d(-0.5,-0.5,0.0);
glVertex3d(0.5,-0.5,0.0);
glVertex3d(0.0,0.5,0.0);
glEnd();
// angle delta equals time delta times omega
double dt=1.0/fps;
angle+=dt*omega;
}
← QGL Class Concept | ● | OpenGL Texturing →