Sign in to follow this  
Chi-

gl List

Recommended Posts

Chi-    100
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:
[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();
}[/code]

all idea of using it is just to increase a preformance when showing 100*100 tiles(GL_QUADS at this point)
when is do
[code]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();
}[/code]
it works but i get 2 fps.
p.s if you have to ask why so many tiles, then it is for zooming.

Share this post


Link to post
Share on other sites
SimonForsman    7642
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 this post


Link to post
Share on other sites
Chi-    100
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 this post


Link to post
Share on other sites
Chi-    100
[quote name='Sponji' timestamp='1333469209' post='4927904']
Why don't you just put all in one list and then make one call to draw all the tiles?
[/quote]
won't that will draw all tiles everytime. what about drawing tiles that are only visable?

Share this post


Link to post
Share on other sites
SimonForsman    7642
[quote name='Chi-' timestamp='1333457387' post='4927850']
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.
[/quote]

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 this post


Link to post
Share on other sites
Chi-    100
@SimonForsman
me my self don't like ppl posting whole code and asking what is wrong. But here is code:
[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();
}[/code]

map drawing is called
[code]// 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();
}[/code]

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

Share this post


Link to post
Share on other sites
SimonForsman    7642
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this