?

Log in

No account? Create an account
 
 
09 November 2004 @ 06:05 pm
Stupid GL!  
This is mostly just a rant about GL being annoying. However if any of the programmers out there happen to know/remember GL and/or general matrix math and have any bright ideas i certainly wouldn't mind hearing them.


I tried to get DirectX 9 working a few weeks ago, and i just couldn't get it to do anything with DevCpp. After giving up on that i decided to try doing something with OpenGL instead, since DevCpp comes with that already installed.

I used GL for graphics back in college and i still have the red book we used then, so i didn't think it would be too hard, and indeed it started out easy enough. I made a couple tanks and added controls so i could move the camera around to look at them from different angles.

So the first problem, which i'd been expecting, is that rotating and moving the camera are in relation to the world axis. As soon as you get the camera out of line of that it stops responding the way you would expect. I've been trying to find the equation for rotating a matrix about an arbitrary axis but haven't had much luck with that. The few webpages i've found suggest either using the DirectX function which does that (which i clearly can't) or something involving the use of the component Euler angles. Unfortunatly i have no idea what the best way to find the component Euler angles is, or how that would really help me figure out what x degrees to the left for an object at a random rotation was.

But anyways i finally gave up on the rotations, at least temporarily, and see if i could at least get translation working right. There should be a way to grab the camera's matrix so i could check the component parts to find out what's forward and what's up and etc. But if there is such a way i don't know what it is. So i figured that since i knew the rotations that went into it then i should just create a vector or two with the initial orientation of the camera and calculate it myself.

So i've written some matrix multiplication functions which should do the job, but i've now run into the most annoying problem. I can't find any bloody way to print error messages!

There's no text window, so i can't use printf. I seem to remember a way you could print messages to the debugger with Visual C++, but if DevCpp has that functionality i haven't figured it out yet. I figured that GL should have some way of printing text to the window, but it doesn't seem to. I tried looking at the font.c demo in the red book and that works fine as long as you're in ortho view, but as soon as i try it with gluPerspective it does nothing =P I could actually draw messages out letter by letter, but that would be a real pain.

The last and most perplexing problem i've run into recently is weird lighlting. I set up lights and material properties for the tanks and everything seemed to be working fine except for the specular aspect. I couldn't see any highlights on them, but i wasn't sure if that was just because they were made up of a few small flat polys or because the lighting was broken. So i tried drawing a sphere with glutSolidSphere. However as soon as i added that all the tanks turned a really dark grey that i can barely see unless i put them between the camera and the sphere. If i comment out that one line that draws the sphere then they all come back. It doesn't make any bloody sense =P


Edit:

I kinda fixed one of the problems


I finally got the camera translation working properly. However in order to do so i had to write a debug function to print messages out to a file, which is just icky. It did help my figure out that one stupid mistake, but since i'm sure there will be more problems later i really wish i could figure out a better solution.
 
 
Current Mood: annoyedannoyed
 
 
 
tierceltiercel on November 9th, 2004 06:13 pm (UTC)
I remember GL!
He was that guy with the green outfit and the lantern and the aversion to yellow, right?
DonAithnendonaithnen on November 9th, 2004 06:25 pm (UTC)
Re: I remember GL!
beeeeeda!
Chaos Never Blinkssithjawa on November 9th, 2004 08:58 pm (UTC)
Funny, I was having just that problem a day ago. What I ended up doing was storing numbers in variables to make the camera work in my coordinate system, and doing it by hand. I think I suck :P

Did you end up doing the transforms with some funky glu function, or by hand?

What the bloody hell do you mean there's no text window/you can't use printf or cout? *I* can, and I'm not using anything special. itslinuxthough... but I thought I remembered that we had a text window when i was developing on VC++ in LSD. Um... could you use cerr? or write to, like, a file? Ugly, but.

I think you may be dealing with a memory problem. I had one when working with glut in LSD and it has to do with some kind of failure to delete some crappy glu object. I had my camera get messed up if I declared an int.

We're still using the red book.
DonAithnendonaithnen on November 10th, 2004 12:53 pm (UTC)
Did you end up doing the transforms with some funky glu function, or by hand?

I already had a matrix multiplication function i'd written, so i wrote some functions to construct rotation matrixes for the X Y and Z axes and made a new matrix to mimic the camera and put it through the same rotations and pulled the forward right and up vectors out of the result.


but I thought I remembered that we had a text window when i was developing on VC++ in LSD.

Note the "developing on VC++" part, which i already said i'm not doing :)

or write to, like, a file? Ugly, but.

And at the end of the post that's what i said that i ended up doing :)

I think you may be dealing with a memory problem. I had one when working with glut in LSD and it has to do with some kind of failure to delete some crappy glu object. I had my camera get messed up if I declared an int.

That sounds really icky =P

Chaos Never Blinkssithjawa on November 10th, 2004 02:21 pm (UTC)
It was icky. I still don't know the exact cause... anyway, if you try declaring an int and it changes your textures, that's probably your problem too. Otherwise all I can think is GLUT doesn't like one of your materials and is restoring it to defaults.
Kirinkirinn on November 10th, 2004 05:08 am (UTC)
Ah, GL stuff. Since I actually do some of this for my job, let's see what I can dredge up.

Rotations: if you really want arbitrary rotations, you might want to look into Quaternions. They specify a rotation using an arbitrary axis and an amount, and it's really easy to compose them, add and subtract them, etc. It's too much to explain in detail here, but I'm sure you can find some tutorials via Google. Oh, and then you'll just need a function to change a quat into a GL rotation matrix when you're done, which I'm sure can be found for free. If you have trouble finding stuff, let me know and I can probably send you something. (Then again, this may all be overkill for what you're doing, not sure.)

Text output: Does the compiler you're using have an option to build as a "console application"? This is what we do sometimes (using MS Dev Studio). This essentially makes your app run from a DOS (or DOS-ish) window, which you can then printf to like normal. (It might be a pain to switch an already existing project to this setup, though, I dunno.) Alternately, I know you can have GL display text in perspective mode because we do it. Although in this case we're not just putting it on the screen (though I'm pretty sure that's possible too), we're actually positioning it in the 3D scene, so you'd have to be looking at it... I can try to look this up later in our code if you need it; something about glRasterPosition and all that.

Bizarre lighting thing when you add a sphere: errrr... that's bizarre. No idea without more debugging info. Maybe glut automatically sets some lighting parameters when you use its solid objects, but I wouldn't think so?
DonAithnendonaithnen on November 10th, 2004 01:01 pm (UTC)
Text output: Does the compiler you're using have an option to build as a "console application"?

Ah! That seems to have worked. Well, at least it opens up a second window as well, i haven't actually tried printing to it yet.

I'm still going to need a way to print stuff in the game later though. How are you guys printing the text? The same way as the font.c example in the red book does, or something else completly? I tried using flRasterPosition with the sample code and it didn't seem to do anything, but i might have just been doing it wrong.

Still though, just printing text at a certain location in the window ought to be a pretty commonly wanted feature. Why the hell don't they have a function for it?

I've bene looking at Quaternions a little, and it looks pretty damn complicated. For starters, how do you directly access the projection or model matrixes?

I've found that if i put the glutSolidSphere at the end of display instead of the begining then things seem to work fine right up until teh first refresh. So yeah, something is strange and fucked up.
Kirinkirinn on November 10th, 2004 03:36 pm (UTC)
Ok, I checked around, and we're actually using a windows GL extension (wgl or something) to do our in-scene text - it provides display lists for the fonts. The wgl stuff comes from (of course) MS Dev Studio, so it's not going to do you much good, however, I hear that there's a free cross platform library that does something very similar (font display lists and calls to draw strings); we just used wgl because it was more convenient. I have a vague memory that you ought to be able to get this to work using only glut too... though I think the results are pretty ugly, which is why people resort to these other font extensions.

If you want to use quats, I think you'll want to figure out the rotation you need and then just use a quat -> gl rotation matrix function and multiply it in to your projection/model matrix like any other rotation. Am I not making sense? It's been a little while since I've messed with it.

It sounds like the glut sphere is changing your material properties by default... and then of course they'll stay changed when drawing your stuff later (if it came first, and you don't change them back explicitly), since GL is all about keeping around the current state...