Advertisement

This is a half opengl/half orthoview question about not drawing offscreen tiles

Started by August 22, 2000 08:54 PM
-1 comments, last by Debonaire Hero 24 years, 4 months ago
I asked around on Nehe''s board but couldn''t get an answer that worked. My problem is this: I have so far a 20 * 10 map of 256X256 pixel tiles, although when drawing to screen it only shows 4 * 3 tiles at 1024*768 resolution. In the drawing loop, I use a double-nested loop to first move everything over by how much the player has moved from his original spot, then draw all 200 tiles. looks like this: glTranslate(x,y,z); // moves over the textures by // how much the player has moved for (row = 0; row < 10; row++) { for (col = 0; col < 20; col++) { glBindTexture(GL_TEXTURE_2D, texture[maparray[row][col]) glBegin(GL_QUADS); //draw the tile .... glEnd(GL_QUADS); glTranslate(256.0,0.0,0.0); // move over for the next tile } glTranslate(-5120.0,256.0,0.0);// move down to next row } while this works quite well in a map so small, eventually this will no longer be feasible as the framerate gets shot to hell while rendering thousands of tiles. I''m trying to figure out how to make a small loop that changes the textures as the player moves around. So far, what I''ve got is this: another double nested loop, this time 4 then 5 (not 3 by 4, because some times you''ve got half of a texture on one side and half on another, then you would have 5 textures, although the ends of the screen would only show part of the textures), then have the program pick the texture by looking through the maparray ( a matrix which stores which texture number the tile should use) and looking at the row then adding the player''s y coordinate divided by 256 and the same for the column with the x coordinate instead. I should subtract 2 from each to get the textures right since the player is in the center of the screen and otherwise, it would use textures from the center and never use textures to the left and top of the player, I think. Then I used the absolute value of the x and y distance the player has traveled and subtracted it to zero every time it got up to 256 so they would never travel beyond the textures on the screen. I then translated the distance they had travelled so the textures would move over an appropriate distance, then translated the row * 256, and the column * 256 for the x and y coords respectively. Then I drew the tile, and loaded identity. BUT IT DOESNT WORK!! All I get it a bunch of tiles with the wrong textures drawn, in a seemingly random order, and the textures usually move in the opposite direction the player is moving and bleh. Well, sorry for this rather lengthy post, but I really need help!

This topic is closed to new replies.

Advertisement