Results 1 to 3 of 3

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

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    2

    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.
    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 :
    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:
    Code :
    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)
    Code :
    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:
    Code :
    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),

    Code :
    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..

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

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

    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Posts
    2

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

    you are great.
    it worked

    thanks

Similar Threads

  1. Can't seem to generate textures!
    By Snow_56767 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-29-2012, 10:54 PM
  2. Generate a tube
    By DannyG in forum OpenGL: General
    Replies: 1
    Last Post: 10-02-2010, 02:12 PM
  3. how to Generate Video
    By aQ in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 05-29-2005, 05:42 PM
  4. how to generate shadows?
    By miko in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 03-02-2003, 08:12 AM
  5. How to generate movies...
    By Mat in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-01-2002, 07:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean