newbie OpenGL questions ......

Started by
19 comments, last by graveyard filla 19 years, 11 months ago
thanks for the help leia, but thats not working. changing the GL_XXX to anything besides GL_RGB gives me an undeclared identifier error. maybe i dont have the latest version or something?i am using vis studio .net 2k3.... also, i tried setting the color like that before drawing my quads, and still no luck... thanks for any more help
FTA, my 2D futuristic action MMORPG
Advertisement
Check out Cone3D's tutorials for how to properly load textures with SDL. SDL's format is not entirely compatible with OpenGL, so you have to flip the image over and maybe fiddle with the color channels, if I remember correctly.

Also, glTexCoord2f(0.0, 0.0) is bottom left. You got the coordinates mixed up.

[edited by - twix on May 20, 2004 2:22:24 PM]
in the nehe tutorial, it says

/* NOTE:
* The x coordinates of the glTexCoord2f function need to inverted
* for SDL because of the way SDL_LoadBmp loads the data. So where
* in the tutorial it has glTexCoord2f( 1.0f, 0.0f ); it should
* now read glTexCoord2f( 0.0f, 0.0f );
*/

thats why i have the stuff flipped around. it doesnt look like the image is flipped, anyway, it looks like the color is screwed up only.. although the image is kind of seamless, so i guess it could be flipped and would be too hard to tell.. i dunno.. guess ill have to check out cone3d after school.. thanks guys...
FTA, my 2D futuristic action MMORPG
also, i dont think it has anything to do with textures...

if i draw a regular white quad, like this, with no texture mapping:

glBegin(GL_QUADS);                /* Draw A Quad */   	  glColor3f(1.0f,1.0f,1.0f);      glVertex2f(player_x,player_y); /* Top Left */	  glVertex2f(player_x + 32.0f,player_y); /* Top Right */	  glVertex2f(player_x + 32.0f,player_y + 32.0f); /* Bottom Right */	  glVertex2f(player_x, player_y + 32.0f); /* Bottom Left */   glEnd();


this quad comes out a dark navy blue just like in the picture!! does anyone know why this is happening?

also - if i change the above code, to make the quad RED instead of white, the navy blue quad turns black! also, if i comment out this line:

glEnable( GL_TEXTURE_2D );

the quad is drawn the way its suposed to! it will come out red if i say red, or white if i say white, but of course, all my textured quads are completely white if i comment this out...

anyone know what the deal is? thanks for any help!
FTA, my 2D futuristic action MMORPG
using your simple "white quad" code, it's draws grey on my computer. I fixed it with this before drawing the quad:

glBindTexture( GL_TEXTURE_2D, 0 );

that binds to a null texture object (assuming you didn't try to create a texture labeled "0")

That doesn't explain the wacked out colors on the quads you are drawing WITH textures though.

The other thing i noticed is that (i think, correct me if i'm wrong) you are drawing your vertices in reverse order. I believe they should be counter-clockwise.

[edited by - leiavoia on May 20, 2004 12:04:39 AM]
i think the drawing is fine (i am drawing counter clockwise) but its something with the texture... i just tried using a different tile that i made just for testing.. the L and R i marked to make sure the image wasnt flipped or anything....

heres what the picture really looks like ( 32x32 image i blew up the pictures so you could see them better)


heres what it looked like rendered in the program


why are the colors acting like this? also, the 'player' which is suposed to be a white quad is a grey quad, earily looking exactly like the grey in the background of my happy face image... i went to cone3d and couldnt find a texture mapping tutorial, maybe im just stupid and didnt see it? i saw a rendering to texture thing, but this isnt what im looking for i dont think...heres the relavent code to the program (its nehes first texture mapping tutorial modified to fill the screen with quads (ie a "map") instead of draw a single cube, also a "player" which is just a white quad drawn to the screen):

int initGL( GLvoid ){	  /* Load in the texture */    if ( !Load_Textures( ) )		return FALSE;    /* Enable Texture Mapping ( NEW ) */	glEnable( GL_TEXTURE_2D);    /* Enable smooth shading */    glShadeModel(GL_SMOOTH);    /* Set the background black */    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );    /* Depth buffer setup */    glClearDepth(1.0f);    /* Enables Depth Testing */    glEnable(GL_DEPTH_TEST);    /* The Type Of Depth Test To Do */    glDepthFunc(GL_LEQUAL);    /* Really Nice Perspective Calculations */    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	return TRUE;}/* Here goes our drawing code */int drawGLScene( GLvoid ){    /* Clear The Screen And The Depth Buffer */    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );    /* Move Left 1.5 Units And Into The Screen 6.0 */    glLoadIdentity();	glColor4f(1.0f,1.0f,1.0f,1.0f);	for(int x = 0; x < 20; x++)	{				for(int y = 0; y < 25; y++)		{			Draw_Quad(x*32,y*32);		}		}	Draw_Player();	/* Draw it to the screen */    SDL_GL_SwapBuffers( );    return( TRUE );}void Draw_Quad(float x, float y){	  glBindTexture(GL_TEXTURE_2D, texture[0]);	  glColor3f(1.0f,1.0f,1.0f);	  glBegin(GL_QUADS);                /* Draw A Quad */   	  glTexCoord2f(0.0f, 1.0f);       glVertex2f(x, y + 32.0f); /* Bottom Left */	  	  glTexCoord2f(1.0f, 1.0f);	  glVertex2f(x + 32.0f,y + 32.0f); /* Bottom Right */	  glTexCoord2f(1.0f, 0.0f); 	  glVertex2f(x + 32.0f,y); /* Top Right */	  glTexCoord2f(0.0f, 0.0f);       glVertex2f(x,y); /* Top Left */     glEnd();}void Draw_Player(){		glBegin(GL_QUADS);                /* Draw A Quad */   	  glColor3f(1.0f,1.0f,1.0f);   	  glVertex2f(player_x,player_y); /* Top Left */	  glVertex2f(player_x + 32.0f,player_y); /* Top Right */	  glVertex2f(player_x + 32.0f,player_y + 32.0f); /* Bottom Right */	  glVertex2f(player_x, player_y + 32.0f); /* Bottom Left */   glEnd();}bool Load_Textures( ){    /* Status indicator */    int Status = 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] = SDL_LoadBMP( "tile1.bmp")))        {		      /* Set the status to true */		      Status = TRUE;		      /* Create The Texture */		      glGenTextures( 1, &texture[0] );			  /* Typical Texture Generation Using Data From The Bitmap */			  glBindTexture( GL_TEXTURE_2D, texture[0] );					  /* Generate The Texture */			  glTexImage2D( GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,TextureImage[0]->h, 0, GL_RGB,							 GL_UNSIGNED_BYTE, TextureImage[0]->pixels );			  /* Linear Filtering */			  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );			  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );        }    /* Free up any memory we may have used */    if (TextureImage[0])	    SDL_FreeSurface(TextureImage[0]);    return Status;}


thanks for any help...

[edited by - graveyard filla on May 20, 2004 12:36:58 AM]

[edited by - graveyard filla on May 20, 2004 12:37:21 AM]

[edited by - graveyard filla on May 20, 2004 12:48:34 AM]
FTA, my 2D futuristic action MMORPG
the image you are loading is being loaded in BGR format, and you are telling OpenGL it is in RGB format, thus the stuff which should be blue is coming out red.

You have a choice:
- Load the image and then convert it to RGB format (I''m sure SDL has a method for doing that)
- Tell OpenGL its a GL_BGR (or maybe it should be GL_BGR_EXT) image instead of a GL_RGB image
yes, your RGB is definately swapped. I can tell just by analyzing the color differences. It looks like BGR ("booger"!). The image you are storing has it''s pixel data reversed, or it''s being read in reverse, or something. Try saving the image as a TGA or PNG and load the file via SDL_image ( IMG_Load() ), or else find some creative way to swap the colors around yourself. Possibly use SDL_ConvertSurface()

The other method is to pass GL_BGR to the teture creation function but i ran into the same problem you mentioned. Window''s supplied version of OpenGL is old. It doesn''t seem to contain the enum values for GL_BGR like my linux version does (libMESA), so you have to find a way to rearrange the pixel data manually as mentioned aboce :-(
thanks guys... that GL_BGR_EXT thing worked.. my texture is normal, but i still have a few problems.. if i resize the window at all, the screen turns completely white... does anyone know what could be causing this? heres my resizing code

when i take input and look for events..
			case SDL_VIDEORESIZE:			    /* handle resize event */			    screen = SDL_SetVideoMode( event.resize.w,event.resize.h,SCREEN_BPP, videoFlags );			    if ( !screen )				{				    fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );				    exit(1);				}			    resizeWindow( event.resize.w, event.resize.h );


in resizeWindow
int resizeWindow( int width, int height ){    /* Protect against a divide by zero */    if ( height == 0 )		height = 1;    /* Setup our viewport. */    glViewport(0,0,width,height);    /* change to the projection matrix and set our viewing volume. */    glMatrixMode(GL_PROJECTION);    glLoadIdentity();	gluOrtho2D(0,width,height,0);	//glOrtho(0.0f,width,height,0.0f,-1.0f,1.0f);    glMatrixMode(GL_MODELVIEW);    /* Reset The View */    glLoadIdentity( );    return TRUE;}



also, another thing that is really bothering me is my window leaves trails when i resize it, or move it below the screen. havent been able to fix this yet..
thanks for anymore help!
FTA, my 2D futuristic action MMORPG
here's mine (hacked up from the same source as you can see :-)

/* function to reset our viewport after a window resize */int resizeWindow( int width, int height ){    /* Protect against a divide by zero */    if ( height == 0 )	height = 1;    /* Setup our viewport. */    glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height );    /* change to the projection matrix and set our viewing volume. */    glMatrixMode( GL_PROJECTION );    glLoadIdentity( );    /* Set our perspective */    // gluPerspective( 45.0f, ratio, 0.1f, 100.0f );    glOrtho(0.0f,width,height,0.0f,-1.0f,1.0f);    /* Make sure we're changing the model view and not the projection */    glMatrixMode( GL_MODELVIEW );    /* Reset The View */    glLoadIdentity( );    return( true );}


[edited by - leiavoia on May 21, 2004 9:05:58 PM]

This topic is closed to new replies.

Advertisement