Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
PalmTreeFun
Apr 25, 2010

*toot*
OpenGL noob here, hoping that someone could give me a bit of help.

Alright, so I want to make a really simple 2D graphics engine with OpenGL. Basically, it would allow you to load in a texture (e.g. a .png using libpng, most likely RGBA format), apply it to a polygonal square or rectangle, and you could rotate or scale it, of course.

I've been trying to read the OpenGL Red Book chapter on texturing, but my mind is seemingly unable to handle the concept of simply putting a texture (or part of one, for animation purposes) on a single, quadrilateral polygon. Can anyone give me a little help here. Also, is there anything else I have to do (reformat the image, take into account byte ordering, setting OGL settings or using glEnable/Disable, etc.) to get this to work properly?

I can't imagine this could be that hard. I have managed to get a polygon drawn to the screen (I'm using GLFW, by the way), and I have a proper real-time loop created (GLFW doesn't use up main() like GLUT). I'm not a complete newbie at OpenGL, but I'm pretty close.

Adbot
ADBOT LOVES YOU

PalmTreeFun
Apr 25, 2010

*toot*

Spite posted:

I'm not sure what your skill level is, but all textures need Texture Coordinates, which are values that determine the texture mapping. A mapping from 0 - 1.0 will give the entire texture in a specific dimension, whereas 0 - 0.5 will give half of it, etc. Usually this means you have two coordinates for the x and y dimensions of a quad. They are usually called s and t.

Do you know how VBOs work? You'll need to set up your data in VBOs (please don't use Begin/End).
You'll also need to Gen and upload the data to the GPU via TexImage2D. You can use glTexParameteri to set the filtering modes. There are Magnification filters (to magnify) and minification filters (to minify). GL_LINEAR is bilinear filtering and GL_LINEAR_MIPMAP_LINEAR is trilinear (which only makes sense for a minification filter).

Then setup the VBO:

glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexPointer(3, GL_FLOAT, 0, NULL);
glBindBuffer(GL_ARRAY_BUFFER, tcVBO);
glTexCoordPointer(2, GL_FLOAT, 0, NULL);

turn on state:

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

bind the texture:

glBindTexture(GL_TEXTURE_2D, tex);
glEnable(GL_TEXTURE_2D);

draw:

glDrawArrays(GL_QUADS, 0, 4);

Try the Superbible/blue book instead of the red book, because the red book is old.

Blue book has been replaced by a reference website.

But anyway, I actually found that Nate Robins' site was very helpful. Being able to play with the values manually helped a lot.

Thank you, though. Especially for the bit about VBO's. I'm sure I can figure out how they work.

PalmTreeFun
Apr 25, 2010

*toot*
Alright, so I'd like to start programming a game in OpenGL. I'm very familiar with C++, and I know how to program a game, but I'm not sure what windowing system would be optimal for this purpose. Should I use GLUT, glfw, or something else?

Also, as far as image loading/writing goes, do I need to check for system endian-ness to manipulate image data? If I make a game cross-platform, I don't want it to start making GBS threads itself, loading and modifying images in the wrong order because some goofy OS reads and writes data backwards.

PalmTreeFun
Apr 25, 2010

*toot*
This is a pretty basic math theory question, but I'm taking a graphics class right now and I need a little help. Long story short, my teacher isn't the best at speaking English, much less at explaining things, and I had to go read the book just to figure out what convolution and reconstruction was. I have that figured out, but what I can't wrap my head around is resampling. You know, scaling images/resampling audio. I understand what it's supposed to do, but I don't quite get the math.

For simplicity's sake, say I'm doing it on audio or some other 1-dimensional data. If I have this data set:

f(x) = 0, 1, 4, 5, 3, 5, 7

And I want to resample this using different filters with a radius of 0.5 in order to figure out, say, f(2.5) and f(2.75), with f(2) having the value 4 in the above data set. My question is, what results should I be getting with my estimates if I use, say, a box filter (1/(2r) if -r <= x < r, 0 otherwise) as opposed to a tent/linear filter (1-abs(x) if abs(x) < 1, 0 otherwise).

I hope I didn't make that too confusing, I just am not sure how to exactly compute resampled values. The book doesn't make it very clear. It says something about taking the data points, reconstructing and smoothing them, then resampling a new set of data, but I don't understand how you convolute two functions (a reconstruction and a smoothing one, as opposed to a function and a data set) together.

PalmTreeFun
Apr 25, 2010

*toot*

Spite posted:

Or am I explaining the wrong thing?

I think so. I understand the part you explained already, but basically what I want to know is how scaling/reconstructing a sound/image works. Like, you convert a set of discrete data to a continuous function somehow, and you can use a kernel (thanks for explaining what that was, I didn't know that that and the "filter" were the same thing, this teacher really sucks at explaining things) to extrapolate new, "in-between" data.

Like, if you used something like a simple average to find a value between elements 1 and 2 (1 and 4) in the example I gave, you'd get a new value 2.5, because that's halfway from one to the other. The problem is, I don't get how you convey different ways of getting new values using a kernel. Same in reverse, shrinking the set instead of expanding it. I had an assignment on the last homework where we had to resample a data set using two different kernels, one being a tent and the other a box, and I had no idea how to compute that.

E: For what it's worth, here are the lecture slides on the topic:

http://pages.cs.wisc.edu/~cs559-1/syllabus/02-01-resampling2/resampling_cont.pdf

Scroll down to the page that says "Resampling".

E2: I just figured out what exactly the box/triangle filters do, (box is rounding up/down, tent is linear interpolation) but I still don't understand how the process in general is done. Like, I have no clue what's going on with the other filters, like Gaussian, B-Spline cubic, Catmull-Rom cubic, etc.

PalmTreeFun fucked around with this message at 00:15 on Feb 10, 2012

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply