Jump to content
  • Advertisement
Sign in to follow this  
guest42

OpenGL 2D 'clipping'

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!