• 15
• 15
• 11
• 9
• 10

# gl List

This topic is 2179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I can't find what is wrong with my gl List. Im new to it. Found many examples on net but can't get to work my.
This is basic of my code:
Tiledmap::Tiledmap(){ ...... initTile(); } void Tiledmap::show(){ ... some "for" loop and glTranslatef glCallList(DrawTile); } void Tiledmap::initTile(){ DrawTile=glGenLists(1); glNewList(DrawTile,GL_COMPILE); glColor4ub(90,90,0,255); glBegin(GL_QUADS); glVertex2f(0,0); glVertex2f(32,0); glVertex2f(32,32); glVertex2f(0,32); glEnd(); glEndList(); }

all idea of using it is just to increase a preformance when showing 100*100 tiles(GL_QUADS at this point)
when is do
void Tiledmap::show(){ ... some "for" loop and glTranslatef glColor4ub(90,90,0,255); glBegin(GL_QUADS); glVertex2f(x,y); glVertex2f(x*32,y); glVertex2f(x*32,y*32); glVertex2f(x,y*32); glEnd(); }
it works but i get 2 fps.
p.s if you have to ask why so many tiles, then it is for zooming.

##### Share on other sites
What doesn't work ? are you getting a compile error ? are you not getting the expected result ?

If the result isn't what you expected then what result are you getting and what result did you expect ?

You probably also want to move glColor4ub out of the list (since its fairly pointless to set it to the same value repeatedly)

Your list code looks fine to me (Havn't used displaylists in ages though so i might be wrong), i'm guessing the problem is in your:
... some "for" loop and glTranslatef
part that you're not showing us.

##### Share on other sites
oh right. problem is that its not drawing the "tile". no errors

glColor4ub is used inside, since i want them all be white when i will applay textures to tiles.

"for" loop is relevant atm. Im trying to draw 1 tile. when i get that done then drawing map with "for" loop will be easy.

##### Share on other sites
Why don't you just put all in one list and then make one call to draw all the tiles?

##### Share on other sites

Why don't you just put all in one list and then make one call to draw all the tiles?

won't that will draw all tiles everytime. what about drawing tiles that are only visable?

##### Share on other sites

oh right. problem is that its not drawing the "tile". no errors

glColor4ub is used inside, since i want them all be white when i will applay textures to tiles.

"for" loop is relevant atm. Im trying to draw 1 tile. when i get that done then drawing map with "for" loop will be easy.

You only have to set the color once, it will use the same color for everything you render until you set it to something else. (The same goes for textures etc aswell, if you draw 2 objects using the same texture you only have to set the texture before drawing the first object) (if everything is textured and you're not actually using glColor to tint the objects you can put one single glColor call in your initialization function and then never have to call it again)

what does your glTranslatef call look like ? , or better yet, just post the damn code (All of it, or atleast a stripped down version of it that compiles and has the same problem) instead of having us guess whats wrong.

##### Share on other sites
@SimonForsman
me my self don't like ppl posting whole code and asking what is wrong. But here is code:
Tiledmap::Tiledmap(){ loadMap(); initTile(); } void Tiledmap::show(){ glColor4ub(200,200,0,255); for(int i = 0; i < size_x; i++){ for(int j = 0; j < size_y; j++){ glPushMatrix(); glTranslatef(i*32,j*32,0); // must understand that even w/o it its not drawing anything ( 32 is tile w/h) glCallList(DrawTile); glPopMatrix(); } } } void Tiledmap::initTile(){ DrawTile=glGenLists(1); glNewList(DrawTile,GL_COMPILE); glBegin(GL_QUADS); glVertex2f(0,0); glVertex2f(32,0); glVertex2f(32,32); glVertex2f(0,32); glEnd(); glEndList(); }

map drawing is called
// set offs if((_player.getX()+10) < win_W/2) offX = 0; else offX = win_W/2-_player.getX()-10; if((_player.getY()+10) < win_H/2) offY = 0; else offY = win_H/2-_player.getY()-10; void Game::gameRender(){ //Clean buffer before start to draw glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(offX,offY,0); //map _tilemap.show(); //player _player.show(); glPopMatrix(); //Swap the buffers SDL_GL_SwapBuffers(); }

When i replace glCallList(DrawTile); with code that is in between glNewList(DrawTile,GL_COMPILE); and glEndList(); it draws everthing as it should be.

##### Share on other sites
Hmm, still alot of code (and thus information missing, are you creating the Tilemap AFTER you've created the OpenGL context ?
post the initialization code.

add a check to ensure that DrawTile isn't 0

use glGetError() after glGenList and after glEndList and check its return value.