void GLWidget::initializeGL( void )
{
mQtGreen
= QColor::fromCmyk( 0.40,
0.0,
1.0,
0.0 );
mQtPurple
= QColor::fromCmyk( 0.39,
0.39,
0.0,
0.0 );
qglClearColor( mQtPurple );
glClearDepth( 1.0f );
mCube->SetColor( mQtGreen.dark() );
glEnable( GL_VERTEX_PROGRAM_ARB );
glEnable( GL_DEPTH_TEST );
glEnable( GL_CULL_FACE );
glShadeModel( GL_SMOOTH );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_MULTISAMPLE );
static GLfloat lightPosition[ 4 ] = { 0.5, 5.0, 7.0, 1.0 };
glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
qDebug() << "GL Initialized" << '\n';
}
void GLWidget::initializeGL( void )
{
mQtGreen = QColor::fromCmyk( 0.40, 0.0, 1.0, 0.0 );
mQtPurple = QColor::fromCmyk( 0.39, 0.39, 0.0, 0.0 );
qglClearColor( mQtPurple );
glClearDepth( 1.0f );
mCube->SetColor( mQtGreen.dark() );
glEnable( GL_VERTEX_PROGRAM_ARB );
glEnable( GL_DEPTH_TEST );
glEnable( GL_CULL_FACE );
glShadeModel( GL_SMOOTH );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_MULTISAMPLE );
static GLfloat lightPosition[ 4 ] = { 0.5, 5.0, 7.0, 1.0 };
glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
qDebug() << "GL Initialized" << '\n';
}
To copy to clipboard, switch view to plain text mode
void GLWidget::paintGL( void )
{
const GLfloat ANGLE_DIVISOR = 16.0;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glTranslatef( 0.0, 0.0, -10.0 );
glRotatef( mXRot / ANGLE_DIVISOR, 1.0, 0.0, 0.0 );
glRotatef( mYRot / ANGLE_DIVISOR, 0.0, 1.0, 0.0 );
glRotatef( mZRot / ANGLE_DIVISOR, 0.0, 0.0, 1.0 );
glMatrixMode( GL_MODELVIEW );
mCube->Draw();
qDebug() << "GL Painted" << '\n';
}
void GLWidget::paintGL( void )
{
const GLfloat ANGLE_DIVISOR = 16.0;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glTranslatef( 0.0, 0.0, -10.0 );
glRotatef( mXRot / ANGLE_DIVISOR, 1.0, 0.0, 0.0 );
glRotatef( mYRot / ANGLE_DIVISOR, 0.0, 1.0, 0.0 );
glRotatef( mZRot / ANGLE_DIVISOR, 0.0, 0.0, 1.0 );
glMatrixMode( GL_MODELVIEW );
mCube->Draw();
qDebug() << "GL Painted" << '\n';
}
To copy to clipboard, switch view to plain text mode
void GLWidget::resizeGL( int width, int height )
{
const GLdouble NEAR = 1;
const GLdouble FAR = 200;
const GLdouble FOVY = 45;
int side = qMin( width, height );
glMatrixMode( GL_PROJECTION );
gluPerspective(
FOVY,
( float ) width / ( float ) height,
NEAR,
FAR
);
glMatrixMode( GL_MODELVIEW );
glViewport( ( width - side ) / VIEWPORT_DIVISOR, ( height - side ) / VIEWPORT_DIVISOR, side, side );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
#ifdef QT_OPENGL_ES_1
glOrthof( -0.5, +0.5, -0.5, +0.5, 4.0, 15.0 );
#else
glOrtho( -0.5, +0.5, -0.5, +0.5, 4.0, 15.0 );
#endif*/
glMatrixMode( GL_MODELVIEW );
qDebug() << "GL Resized" << '\n';
}
void GLWidget::resizeGL( int width, int height )
{
const GLdouble NEAR = 1;
const GLdouble FAR = 200;
const GLdouble FOVY = 45;
int side = qMin( width, height );
glMatrixMode( GL_PROJECTION );
gluPerspective(
FOVY,
( float ) width / ( float ) height,
NEAR,
FAR
);
glMatrixMode( GL_MODELVIEW );
glViewport( ( width - side ) / VIEWPORT_DIVISOR, ( height - side ) / VIEWPORT_DIVISOR, side, side );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
#ifdef QT_OPENGL_ES_1
glOrthof( -0.5, +0.5, -0.5, +0.5, 4.0, 15.0 );
#else
glOrtho( -0.5, +0.5, -0.5, +0.5, 4.0, 15.0 );
#endif*/
glMatrixMode( GL_MODELVIEW );
qDebug() << "GL Resized" << '\n';
}
To copy to clipboard, switch view to plain text mode
void Cube::RenderCube( const unsigned short type, const QPoint3 &position, const int size )
{
( *mCubeage )[ "cubes" + '\0' ] += 1;
SetColor( type );
int x1 = 0, x2 = 0;
int y1 = 0, y2 = 0;
int z1 = 0, z2 = 0;
x1 = position.x() - size;
x2 = position.x() + size;
y1 = position.y() - size;
y2 = position.y() + size;
z1 = ( position.z() - size ) + 1;
z2 = position.z() + size + 1;
qreal camZ = mCamera->z();
qreal camY = mCamera->y();
qreal camX = mCamera->x();
glMatrixMode( GL_PROJECTION );
glTranslatef( 0.0, 0.0, -10.0 );
glOrtho( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
glMatrixMode( GL_MODELVIEW );
/*
* if axis > mCamera.axis; then normal3f -1.0 on the axis.
* axis point is axis1
* else if axis < mCamera.axis; then nomral3f 1.0 on the axis.
* axis point is axis2
*/
/* Pattern: one axis is written twice, with the other variant of the same axis written twice as well, then the
* order at which those axes are written is flipped, yet still following the same pattern.
* Pattern2: one type of axis is still written twice, and the other group of the same axis written twice as well,
* the only difference being that the first group is written once, with the next group written twice, and then that
* first group written once again. The third axis type is written using one type, depending on the camera comparisons.
*/
const bool PUSH_AND_POP_MATRIX = ( CheckMinMatrixStack( GL_MODELVIEW ) );
if ( PUSH_AND_POP_MATRIX )
glPushMatrix;
glBegin( GL_QUADS );
if ( z1 > camZ )
{
glNormal3f( 0.0, 0.0, -1.0 );
glVertex3i( x1, y1, z1 ); //1
glVertex3i( x1, y2, z1 ); //1
glVertex3i( x2, y2, z1 ); //1
glVertex3i( x2, y1, z1 ); //1
}
if ( z2 < camZ )
{
glNormal3f( 0.0, 0.0, 1.0 );
glVertex3i( x2, y1, z2 ); //2
glVertex3i( x2, y2, z2 ); //2
glVertex3i( x1, y2, z2 ); //2
glVertex3i( x1, y1, z2 ); //2
}
if ( y1 > camY )
{
glNormal3f( 0.0, -1.0, 0.0 );
glVertex3i( x2, y1, z1 );
glVertex3i( x2, y1, z2 );
glVertex3i( x1, y1, z2 );
glVertex3i( x1, y1, z1 );
}
if ( y2 < camY )
{
glNormal3f( 0.0, 1.0, 0.0 );
glVertex3i( x1, y2, z1 );
glVertex3i( x1, y2, z2 );
glVertex3i( x2, y2, z2 );
glVertex3i( x2, y2, z1 );
}
if ( x1 > camX )
{
glNormal3f( -1.0, 0.0, 0.0 );
glVertex3i( x1, y1, z1 );
glVertex3i( x1, y1, z2 );
glVertex3i( x1, y2, z2 );
glVertex3i( x1, y2, z1 );
}
if ( x2 < camX )
{
glNormal3f( 1.0, 0.0, 0.0 );
glVertex3i( x2, y2, z1 );
glVertex3i( x2, y2, z2 );
glVertex3i( x2, y1, z2 );
glVertex3i( x2, y1, z1 );
}
glEnd();
if ( PUSH_AND_POP_MATRIX )
glPopMatrix();
}
void Cube::RenderCube( const unsigned short type, const QPoint3 &position, const int size )
{
( *mCubeage )[ "cubes" + '\0' ] += 1;
SetColor( type );
int x1 = 0, x2 = 0;
int y1 = 0, y2 = 0;
int z1 = 0, z2 = 0;
x1 = position.x() - size;
x2 = position.x() + size;
y1 = position.y() - size;
y2 = position.y() + size;
z1 = ( position.z() - size ) + 1;
z2 = position.z() + size + 1;
qreal camZ = mCamera->z();
qreal camY = mCamera->y();
qreal camX = mCamera->x();
glMatrixMode( GL_PROJECTION );
glTranslatef( 0.0, 0.0, -10.0 );
glOrtho( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 );
glMatrixMode( GL_MODELVIEW );
/*
* if axis > mCamera.axis; then normal3f -1.0 on the axis.
* axis point is axis1
* else if axis < mCamera.axis; then nomral3f 1.0 on the axis.
* axis point is axis2
*/
/* Pattern: one axis is written twice, with the other variant of the same axis written twice as well, then the
* order at which those axes are written is flipped, yet still following the same pattern.
* Pattern2: one type of axis is still written twice, and the other group of the same axis written twice as well,
* the only difference being that the first group is written once, with the next group written twice, and then that
* first group written once again. The third axis type is written using one type, depending on the camera comparisons.
*/
const bool PUSH_AND_POP_MATRIX = ( CheckMinMatrixStack( GL_MODELVIEW ) );
if ( PUSH_AND_POP_MATRIX )
glPushMatrix;
glBegin( GL_QUADS );
if ( z1 > camZ )
{
glNormal3f( 0.0, 0.0, -1.0 );
glVertex3i( x1, y1, z1 ); //1
glVertex3i( x1, y2, z1 ); //1
glVertex3i( x2, y2, z1 ); //1
glVertex3i( x2, y1, z1 ); //1
}
if ( z2 < camZ )
{
glNormal3f( 0.0, 0.0, 1.0 );
glVertex3i( x2, y1, z2 ); //2
glVertex3i( x2, y2, z2 ); //2
glVertex3i( x1, y2, z2 ); //2
glVertex3i( x1, y1, z2 ); //2
}
if ( y1 > camY )
{
glNormal3f( 0.0, -1.0, 0.0 );
glVertex3i( x2, y1, z1 );
glVertex3i( x2, y1, z2 );
glVertex3i( x1, y1, z2 );
glVertex3i( x1, y1, z1 );
}
if ( y2 < camY )
{
glNormal3f( 0.0, 1.0, 0.0 );
glVertex3i( x1, y2, z1 );
glVertex3i( x1, y2, z2 );
glVertex3i( x2, y2, z2 );
glVertex3i( x2, y2, z1 );
}
if ( x1 > camX )
{
glNormal3f( -1.0, 0.0, 0.0 );
glVertex3i( x1, y1, z1 );
glVertex3i( x1, y1, z2 );
glVertex3i( x1, y2, z2 );
glVertex3i( x1, y2, z1 );
}
if ( x2 < camX )
{
glNormal3f( 1.0, 0.0, 0.0 );
glVertex3i( x2, y2, z1 );
glVertex3i( x2, y2, z2 );
glVertex3i( x2, y1, z2 );
glVertex3i( x2, y1, z1 );
}
glEnd();
if ( PUSH_AND_POP_MATRIX )
glPopMatrix();
}
To copy to clipboard, switch view to plain text mode
void Cube::RenderVB( unsigned short type, const QPoint3F &position, int size )
{
static const GLuint NUM_COORDS_PER_VERTEX = 3;
static const GLuint NUM_ARR_TO_DRAW = 24;
static const GLuint FIRST_INDEX_TO_DRAW = 0;
( *mCubeage )[ "cubes" ] += 1;
SetColor( type );
glMatrixMode( GL_PROJECTION );
const bool pushAndPop = CheckMinMatrixStack( GL_PROJECTION );
if ( pushAndPop )
glPushMatrix();
glTranslatef( position.x(), position.y(), position.z() );
glScalef( size, size, size );
glVertexPointer( NUM_COORDS_PER_VERTEX, GL_FLOAT, sizeof( QPoint3F ), ( void* ) ( sizeof( QPoint3F ) * 24 ) );
glNormalPointer( GL_FLOAT, sizeof( QPoint3F ), 0 );
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glDrawArrays( GL_QUADS, FIRST_INDEX_TO_DRAW, NUM_ARR_TO_DRAW);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
if ( pushAndPop )
glPopMatrix();
}
void Cube::RenderVB( unsigned short type, const QPoint3F &position, int size )
{
static const GLuint NUM_COORDS_PER_VERTEX = 3;
static const GLuint NUM_ARR_TO_DRAW = 24;
static const GLuint FIRST_INDEX_TO_DRAW = 0;
( *mCubeage )[ "cubes" ] += 1;
SetColor( type );
glMatrixMode( GL_PROJECTION );
const bool pushAndPop = CheckMinMatrixStack( GL_PROJECTION );
if ( pushAndPop )
glPushMatrix();
glTranslatef( position.x(), position.y(), position.z() );
glScalef( size, size, size );
glVertexPointer( NUM_COORDS_PER_VERTEX, GL_FLOAT, sizeof( QPoint3F ), ( void* ) ( sizeof( QPoint3F ) * 24 ) );
glNormalPointer( GL_FLOAT, sizeof( QPoint3F ), 0 );
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glDrawArrays( GL_QUADS, FIRST_INDEX_TO_DRAW, NUM_ARR_TO_DRAW);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
if ( pushAndPop )
glPopMatrix();
}
To copy to clipboard, switch view to plain text mode
Bookmarks