iDevGames Forums
opengl view question - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: opengl view question (/thread-3154.html)



opengl view question - Leroy - Jul 23, 2007 05:50 PM

Something very strange is happening in my engine's tile drawing routine(s)(tiles=textured quads). I normally draw only the tiles which are visible(and nearly visible so there's no abrupt popping of tiles) but for some odd reason opengl initially only draws tiles which are immediately and completely within the bounds of the window or view.

If I decrease the size of the view/window, everything is drawn properly(I don't have any special reshape function if it makes any difference).

The pic on the right is how it appears normally, and the pic on the left is after I have decreased the size of the window/view(after decreasing it, I can then resize it anyway I like and everything will still draw properly.

http://web.mac.com/aleister55/iWeb/Site/Blank%202.html

Anyone have an idea of what might be going on?


opengl view question - wyrmmage - Jul 23, 2007 06:25 PM

sounds like your algorithm for checking if tiles are "nearly visible so there's no abrupt popping of tiles" is accounting for the resizing of the window. (or calculating it wrong somehow); can you post the code that conducts that test?
-wyrmmage


opengl view question - Leroy - Jul 23, 2007 06:32 PM

wyrmmage Wrote:sounds like your algorithm for checking if tiles are "nearly visible so there's no abrupt popping of tiles" is accounting for the resizing of the window. (or calculating it wrong somehow); can you post the code that conducts that test?
-wyrmmage

No it's not my drawing code(it doesn't matter if I draw the entire map or only the visible+near visible tiles), the code itself is fine.

Anyways, here's my viewport setup:
Code:
NSRect viewBounds = [self bounds];
gluOrtho2D(0, viewBounds.size.width,
               0, viewBounds.size.height);

The only thing(with my extremely limited knowledge of opengl) that comes to mind is that somehow the clipping planes are initially set to the bounds of my viewport, and perhaps somehow resizing the window extends them or something? I don't know, but I can't begin to figure out what's happening


here's the drawing function(which draws the entire map for the sake of my testing purposes):


Code:
void draw_tiles2(void)
{
    int x, y, layer = 0;
    NSPoint pixel, tile;
    quad2d_type tile_quad;
    
    
    
    for (layer = 0; layer < 8; layer++)
    

        for (y  = MAP_HEIGHT; y > -1; y--){
                for (x = 0; x < MAP_WIDTH; x++){
                if (g_tile_map[x][y][layer].active)
                {
            
                
                    tile = NSMakePoint(x,y);
                    pixel = convert_point_tile_to_world(tile);
                    create_tile_quad( &tile_quad, g_tile_map[x][y][layer],
                                pixel.x, pixel.y);
                    draw_quad(&tile_quad);
                }
            }
        }
    
}



opengl view question - AnotherJake - Jul 23, 2007 11:08 PM

Leroy Wrote:No it's not my drawing code(it doesn't matter if I draw the entire map or only the visible+near visible tiles), the code itself is fine.
Well OpenGL is certainly not culling your quads, so that only leaves your code suspect...