2D 'clipping'

Started by
1 comment, last by smitty1276 16 years, 9 months ago
Hi! I am new to OpenGL, and as of now I am starting to make a 2D top down game using vector graphics, using C.. I'm going to have grid lines running across the floor that that will scroll as the player moves to give the appearance that the player is moving (Kinda like Warning Forever, but you're not constantly moving). This was some java code that did the same thing that I will copy over once I've worked on some other things. 'view' is a rectangle object representing the area around the character in the center of the screen that the player can see. The grid will be 64x64 squares. The offsets are just for extra view offset from 'earthquake' effects and what have you: int vx = view.x%64; int vy = view.y%64; for(int i = 0; i <= view.width+64; i+=64) { g.drawLine((i-vx)-offsetX, 0, (i-vx)-offsetX, view.height); } for(int i = 0; i <= view.height+64; i+=64) { g.drawLine(0, (i-vy)-offsetY, view.width, (i-vy)-offsetY); } Okay, with that being said, these lines would be drawn all across the screen. What I want to do is have them only show inside of polygonal shapes, which will represent platforms the player can walk on, where as the rest of the screen represents 'void' and has no floor grid. In other words, if you have a sheet of grid paper and lay another black sheet of paper over that, you will only be able to see the grid paper where you've cut shapes out of the black paper. In Java I believe this was 'clipping', but I think that has another meaning in OpenGL. Anyway, does anyone know how I can achieve this effect? Is there some facility in OpenGL, or is there a pixel per pixel algorithm I have to use? Any help would be appreciated.
Advertisement
Look up stencil test and scissor test. Either one should be able to give you the result you are looking for.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
If you're trying to draw "platforms", you probably don't want the lines moving to indicate motion.... you actually need to make the polygons move. Depending on exactly what you're shooting for, you might be better off by just drawing polygons for the platforms and texturing them with the grid lines.

This topic is closed to new replies.

Advertisement