View Full Version : 2D Clipping
05-05-2004, 09:13 PM
I am writing a 2D rpg using openGL and the images I use to draw sprites have 12 seperate renditions of a character. Previously I was writing this in java using Java2D, but I decided to learn openGL. So my question is basicaly how to do 2-Dimensional clipping in openGL. My guess is that it will be the same as 3D (which I also don't know), so any information on it or perhaps pointing me to a tutorial would be helpful, thanks!
05-06-2004, 01:27 AM
Have a look at http://www.cc.gatech.edu/grads/h/Hao-wei.Hsieh/Haowei.Hsieh/mm.html
It explains the Cohen-Sutherland an Sutherland-Hodman algorithms for clipping.
05-06-2004, 07:45 AM
What is the point of doing clipping yourself ? Can you elaborated a bit more what you mean ?
05-06-2004, 10:40 AM
thanks -NiCo-, I will read through that. zbuffer, I'm not sure what you mean by why would I do it myself. Do you mean I should split up the images into seperate tiles before running the program? I do this so I dont have to load so many images and to keep stuff organized. Chipsets are generally just one image and I use clipping to break them up and tile them onto the page in the shape of a map made with my editor. For character animation I just change the position of the clip on the image of my character to display a different frame of animation.
05-06-2004, 10:42 AM
*correction: This is what I was doing while using java2D, I may have to change this for openGL I'm am completely new to the language and not sure how this kind of thing is done.
05-06-2004, 11:09 AM
Ok, I understand a bit better what you want to do.
Drawing 2D tiles and sprites in opengl is like drawing 2d quads (square or rectangle), which are texture-mapped using the right texture coordinates.
Just by putting the right texcoords you will be able to select the part of the texture that will be visible. The only trick is that OpenGL textures must be power of two, that is 256*256 or 128*1024, etc. So you have to pad the unused areas.
You can use alpha testing or blending for transparency effects.
05-06-2004, 11:37 AM
The only trick is that OpenGL textures must be power of two, that is 256*256 or 128*1024, etc. This is not necesseraly true, but it's a good start since you said that you are new to OpenGL and probably don't know how to use some special OpenGL extensions.
If you want to explore it a little further, take a look at http://oss.sgi.com/projects/ogl-sample/registry/
There are two extensions that allow you to specify textures of non-power-of-2 dimensions called GL_NV_texture_rectangle and GL_ARB_texture_non_power_of_two.
For now, it's best you read the opengl specification at http://www.opengl.org/documentation/specs/version1.5/glspec15.pdf
05-06-2004, 04:07 PM
thanks for the help guys, fortunately all the tiles I am using for my chipsets (maps) are powers of 2, unfortunately my character tiles vary in size so I will have to attempt one of the techniques your described previously. If I were to use an extension, does this limit the number of people that can use my game because their graphics card has to support it, or is it something I can ship with my game?
05-07-2004, 01:27 AM
Because GL_NV_TEXTURE_RECTANGLE is an Nvidia specific extension, it is not supported by Ati graphics cards. So for now you'll have to create two seperate programming paths using preprocessing macros, which can be tedious work because texture coordinates are defined differently for the two extensions mentioned in my previous post.
If you are looking for compatibility of your programs, it's always best to constrain your program to use only ARB and EXT extensions, and avoid NV and ATI extensions.
05-07-2004, 09:59 PM
Ok, that about covers everything. Thanks for all the help guys, this should set me down the right path!
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.