Name: Anonymous 2010-11-13 14:52
So /anus/, I've been reading tutorials on openGL and how to render textures to the screen, but whenever i try all i get is a black box
here is my texture loading code
and the render code:
here is my texture loading code
GLuint LoadTexture(const char *filename)
{
GLuint texture = FALSE;
/* Create storage space for the texture */
SDL_Surface *TextureImage[1];
/* Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit */
if ( ( TextureImage[0] = IMG_Load( filename ) ) )
{
/* Create The Texture */
glGenTextures( 1, &texture );
/* Load in texture 1 */
/* Typical Texture Generation Using Data From The Bitmap */
glBindTexture( GL_TEXTURE_2D, texture);
//create the image
glTexImage2D(GL_TEXTURE_2D,
0,
4, //alpha enabled
TextureImage[0]->w,
TextureImage[0]->h,
0,
GL_RGBA, //HERP
GL_UNSIGNED_BYTE,
TextureImage[0]->pixels);
/* Nearest Filtering */
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
}
/* Free up any memory we may have used */
if ( TextureImage[0] )
SDL_FreeSurface( TextureImage[0] );
return texture;
}and the render code:
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
/* Clear The Screen And The Depth Buffer */
glClearColor(1.0f,1.0f,1.0f,0.0f); //white
glClear( GL_COLOR_BUFFER_BIT );
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,anus);
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2d(50.0,50.0);
glTexCoord2d(1.0,0.0); glVertex2d(90.0,50.0);
glTexCoord2d(1.0,1.0); glVertex2d(90.0,90.0);
glTexCoord2d(0.0,1.0); glVertex2d(50.0,90.0);
glEnd();
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();