void init( char *a )
{
glClearColor( 0.6f, 0.8f, 0.2f, 0.0f );
glShadeModel( GL_SMOOTH );
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
init_VBO();
load_tex( a );
init_light();
}
void init_light()
{
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 10.0 };
GLfloat white_light[] = { 1.0, 1.0, 0.5, 1.0 };
GLfloat lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { -6.0, 7.0, 6.0, 1.0 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//glLightfv(GL_LIGHT0, GL_AMBIENT, white_light); //similar?
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient );
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
}
static void display(void)
{
glMatrixMode( GL_MODELVIEW ); // do NOT switch MatrixMode every frame!
glLoadIdentity(); // do NOT loadidentity ever frame (use push/popmatrix instead)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindBuffer( GL_ARRAY_BUFFER, VBO );
glBindTexture( GL_TEXTURE_2D, tex[tex_id] );
glVertexPointer( 3, GL_FLOAT, sizeof(GLfloat)*5, BUFFER_OFFSET(0) ); // Set The Vertex Pointer To The Vertex Buffer
glTexCoordPointer( 2, GL_FLOAT, sizeof(GLfloat)*5, BUFFER_OFFSET( sizeof(GLfloat)*3 ) );
glColor3f( 1.f, 1.f, 1.f );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable (GL_TEXTURE_2D);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glDrawArrays( GL_QUADS, 0, 4 ); // 4 == vertex count
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );
glDisable (GL_TEXTURE_2D);
//glDisable(GL_DEPTH_TEST);
glEnable( GL_BLEND );
glTranslatef( 0.f, 2.f, 0.f );
glColor4f( 1.f, 0.f, 1.f, 1.0f );
glutSolidCube( 4.0 );
glColor4f( 0.f, 0.f, 1.f, 1.0f );
glBegin(GL_QUADS);
// quick trick: 1.f(normal) is where the column of numbers(vertex) are the same!
glNormal3f( 0.f, 1.f, 0.f );
glVertex3f( 4.0f, 4.0f,-4.0f); // Top Right Of The Quad (Top)
glVertex3f(-4.0f, 4.0f,-4.0f); // Top Left Of The Quad (Top)
glVertex3f(-4.0f, 4.0f, 4.0f); // Bottom Left Of The Quad (Top)
glVertex3f( 4.0f, 4.0f, 4.0f); // Bottom Right Of The Quad (Top)
glNormal3f( 0.f, -1.f, 0.f );
glVertex3f( 4.0f,-4.0f, 4.0f); // Top Right Of The Quad (Bottom)
glVertex3f(-4.0f,-4.0f, 4.0f); // Top Left Of The Quad (Bottom)
glVertex3f(-4.0f,-4.0f,-4.0f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 4.0f,-4.0f,-4.0f); // Bottom Right Of The Quad (Bottom)
glNormal3f( 0.f, 0.f, 1.f );
glVertex3f( 4.0f, 4.0f, 4.0f); // Top Right Of The Quad (Front)
glVertex3f(-4.0f, 4.0f, 4.0f); // Top Left Of The Quad (Front)
glVertex3f(-4.0f,-4.0f, 4.0f); // Bottom Left Of The Quad (Front)
glVertex3f( 4.0f,-4.0f, 4.0f); // Bottom Right Of The Quad (Front)
glNormal3f( 0.f, 0.f, -1.f );
glVertex3f( 4.0f,-4.0f,-4.0f); // Top Right Of The Quad (Back)
glVertex3f(-4.0f,-4.0f,-4.0f); // Top Left Of The Quad (Back)
glVertex3f(-4.0f, 4.0f,-4.0f); // Bottom Left Of The Quad (Back)
glVertex3f( 4.0f, 4.0f,-4.0f); // Bottom Right Of The Quad (Back)
glNormal3f( -1.f, 0.f, 0.f );
glVertex3f(-4.0f, 4.0f, 4.0f); // Top Right Of The Quad (Left)
glVertex3f(-4.0f, 4.0f,-4.0f); // Top Left Of The Quad (Left)
glVertex3f(-4.0f,-4.0f,-4.0f); // Bottom Left Of The Quad (Left)
glVertex3f(-4.0f,-4.0f, 4.0f); // Bottom Right Of The Quad (Left)
glNormal3f( 1.f, 0.f, 0.f );
glVertex3f( 4.0f, 4.0f,-4.0f); // Top Right Of The Quad (Right)
glVertex3f( 4.0f, 4.0f, 4.0f); // Top Left Of The Quad (Right)
glVertex3f( 4.0f,-4.0f, 4.0f); // Bottom Left Of The Quad (Right)
glVertex3f( 4.0f,-4.0f,-4.0f); // Bottom Right Of The Quad (Right)
glEnd(); // Done Drawing The Pyramid
glDisable( GL_BLEND );
//glEnable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
glutSwapBuffers();
}
simple blending problem
Hello all!
I've just went through the 8th NeHe's lesson(blending) and it seems that when I change the alpha values in glColor4f() funct, nothing changes the scene!
I have fiddled around with different blending functions and sorted the polys from farthest to nearest, but still nothing changes the transparency of the (two) polys in the scene.
I have a gf2mx, the latest glext.h and the latest drivers installed.
Also, glGetError() reports that there were no errors.
relevant functions:
btw, with this code, even with alpha values set to 1.0f in glColor4f(), it makes the two polys transparent.
Thank you!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement