I’m going nuts trying to figure this out, i have code to load a bitmap and all, and i did all the necessary nonsense to generate a texture but all my triangles still appear as white solid triangles. But here is the weirdest part: (using dev-cpp) i started a new glut project, took some of the loading and drawing code from the project i’m trying to get to work, pasted it in the new glut project, and it worked! I don’t understand it at all.
Some code snippets:
void Reshape( int width, int height )
{
game.gameMenu.hScreenWidth = width / 2;
game.gameMenu.hScreenHeight = height / 2;
glEnable( GL_BLEND ); // code for transparency
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glViewport(0, 0, width, height);
glMatrixMode( GL_PROJECTION ); // Change to 1 pixel per gl unit
glLoadIdentity();
glOrtho( -width/2, width/2, height/2, -height/2, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
}
void GamePlay::draw( )
{
glLoadIdentity( );
glRotatef( angle, 0.0, 0.0, 1.0 );
glScalef( scaleFactor, scaleFactor, 0.0 );
glTranslatef( -players[ myIndex ].position.x, -players[ myIndex ].position.y, -200.0f );
for( int i = 0; i < numTris; i++ )
{
glBindTexture( GL_TEXTURE_2D, texs[ tris[ i ].texIndex ] );
glBegin( GL_TRIANGLES );
glTexCoord2f( 0.0, 1.0 );
glVertex2f( tris[ i ].v[ 0 ].x, tris[ i ].v[ 0 ].y );
glTexCoord2f( 1.0, 1.0 );
glVertex2f( tris[ i ].v[ 1 ].x, tris[ i ].v[ 1 ].y );
glTexCoord2f( 0.0, 0.0 );
glVertex2f( tris[ i ].v[ 2 ].x, tris[ i ].v[ 2 ].y );
glEnd( );
}
for( int i = 0; i < players.size( ); i++ )
{
players[ i ].draw( );
}
}
void GamePlay::loadMap ( char * filename )
{
ifstream mapFile( filename );
mapFile >> numTris;
tris = new Triangle [ numTris ];
mapFile >> numTexs;
mapFile.get();
filenames = new char * [ numTexs ];
for( int i = 0; i < numTexs; i++ )
{
filenames[ i ] = new char [ 32 ];
mapFile.getline( filenames[ i ], 32, '
' );
}
for( int i = 0; i < numTris; i++ )
{
for( int j = 0; j < 3; j++ )
{
mapFile >> tris[ i ].v[ j ].x;
mapFile >> tris[ i ].v[ j ].y;
}
mapFile >> tris[ i ].texIndex;
}
mapFile.close( );
}
void GamePlay::loadTexs ( )
{
Bitmap24Bit bmp;
texs = new GLuint [ numTexs ];
glGenTextures( numTexs, &texs[ 0 ] );
for( int i = 0; i < numTexs; i++ )
{
bmp.loadBMP( filenames[ i ] );
glBindTexture( GL_TEXTURE_2D, texs[ i ] );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bmp.width, bmp.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp.imageData );
bmp.releaseData();
}
}
int main(int argc, char **argv)
{
glutInit( &argc, argv );
Init();
// Declare the display, idle, reshape, and keyboard functions
glutDisplayFunc( Draw );
glutKeyboardFunc( Keyboard );
glutKeyboardUpFunc( KeyboardUp );
glutMouseFunc( Mouse );
glutPassiveMotionFunc( MouseMotion );
glutReshapeFunc( Reshape );
glutIdleFunc( Idle );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LESS );
glEnable( GL_TEXTURE_2D );
// Start the Main Loop
glutMainLoop();
return true;
}
All the initialization stuff is nearly identical or at some point was because i was changing every little thing trying to get something to work but nothing did. So basically i’m really confused. It may have something to do with the networking library i’m using (RakNet).
A weird thing about RakNet is that i had everything working… then i started getting this segfault, and went crazy trying to solve it, someone told me to change some lines in one of the headers and i did but nothing changed. I eventually solved the problem, so now i was messing around with things, and i decided to take out the lines that the person told me to put in… all of a sudden, my menu stopped working. I found out the problem was that a variable was assigning itself some weird values… i don’t know how though, because i cout’ed the only line where it was being changed or accessed and it printed out the right value, then i cout’ed where the variable was being used and it was all wrong. So go figure…
Sorry for the essay-like question