I cant generate what i want or i just cant see it

Hi, first of all, im a newbie at opengl and this is (i think) a super newbie question. :stuck_out_tongue:
Ive done some games before, and now im making a very simple 2D rts in c++. (like warcraft1)
My problem is that i want to display a menu (quad with texture) and i dont know if it was generated or just that i cant see it (the quad or the texture). I’ve been searching, and i think im doing something wrong when i do the graphics initialization. But ive tried everything that i know, and now i really need some expert advice.

Here’s my graphic initialization code :


bool cGame::Init()
{
	bool res = true;

	//Graphics initialization
	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,GAME_WIDTH,0,GAME_HEIGHT,0,1);
	glMatrixMode(GL_MODELVIEW);
	
	glAlphaFunc(GL_GREATER, 0.05f);
	glEnable(GL_ALPHA_TEST);

	//Scene initialization
	res = Data.LoadImage(IMG_MENU, "MENU.bmp", GL_RGB);
	if(!res) return false;
	Scene.LoadMenu();

	return res;
}   

Here’s where i load the image to the data:

bool cData::LoadImage(int img, char *filename, int type)
{
	int res;

	res = texture[img].Load(filename, type);
	if(!res) return false;
	return true;
}

Load the texture: (i dont think the problem is in here)


bool cTexture::Load(char *filename,int type,int wraps,int wrapt,int magf,int minf,bool mipmap)
{
	corona::Image* img;
	int components;

	img = corona::OpenImage(filename);
	if(type == GL_RGB)
	{
		//img = corona::OpenImage(filename,corona::PF_R8G8B8);
		components = 3;
	}
	else if(type == GL_RGBA)
	{
		//img = corona::OpenImage(filename,corona::PF_R8G8B8A8);
		components = 4;
	}
	else return false;

	if(img == NULL) return false;

	width  = img->getWidth();
	height = img->getHeight();

	glGenTextures(1, &id);
	glBindTexture(GL_TEXTURE_2D, id);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wraps);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapt);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magf);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minf);

	if(!mipmap)
	{
		glTexImage2D(GL_TEXTURE_2D, 0, components, width, height, 0, type,
					 GL_UNSIGNED_BYTE, img->getPixels());
	}
	else
	{
		gluBuild2DMipmaps(GL_TEXTURE_2D, components, width, height, type,
						  GL_UNSIGNED_BYTE, img->getPixels());
	}

	return true;
}

And here where i display the texture:

void cScene::LoadMenu() {
	glNewList(ESTADO_MENU, GL_COMPILE);
		glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
	glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 0.0f);
	glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, 0.0f);
	glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, 0.0f);
		glEnd();
	glEndList();
}

So i compile this list and i call it (works),

glEnable(GL_TEXTURE_2D);						
	glBindTexture(GL_TEXTURE_2D, tex_id);
	glPushMatrix();
		glCallList(estado_game);
	glPopMatrix();
glDisable(GL_TEXTURE_2D);

but i get no quad with the texture.
the image:
400x400 .bmp

Thanks…

  1. You set the projection matrix to
    glOrtho(0,GAME_WIDTH,0,GAME_HEIGHT,0,1);
    but as far as I can tell you don’t scale the vertices of the display list, meaning that if you have a viewport size of GAME_WIDTHxGAME_HEIGHT only a quarter of the quad will be visible in the bottom left pixel.

  2. Your orthographic depth range equals [0,1] and you’re drawing the quad at depth 0 so it’s possible that it’s being clipped at the rasterization stage.

  3. You may want to remove the alpha_test temporarily when debugging.

you are great.
it worked

thanks