Hey guys,
I'm working on a 3-D OpenGL game and am using Allegro. However, I have no idea how to do this (with Allegro, that is, I understand OpenGL).
Here's some code:
Pardon how hideous it is, lacking any form of error checking and all. I'm just trying to figure out how Allegro and OpenGL work together. I'm sure a few of those calls aren't even necessary, but I've been trying everything to get something other than a blank, black screen.
Any help would be greatly, GREATLY appreciated.
- Luiji
One thing that comes to mind, I think Allegro does not set a depth buffer, check this out to set one:
http://www.liballeg.org/a5docs/refman/display.html#al_set_new_display_option
ALLEGRO_DEPTH_SIZE
How many depth buffer (z-buffer) bits to use.
You might also want to check out:
ex_opengl.c
Hm, I've modified the code to set the ALLEGRO_DEPTH_SIZE to 30 (sort of a random number, I figured it'd be big enough to play with later):
However, now my program aborts with "cube: failed to create display". It seems that Allegro can't set the z-depth. I don't think it's anything wrong with my hardware/drivers, though, since GlxGears runs perfectly and I'm pretty sure that it uses a z-buffer, too.
Thanks,
- L
I'm pretty sure z buffer sizes are limited to 16, 24 or 32 bits, since it's bits per element, it might have been better if they'd specified how many bytes per element, not bits.
Ah, I totally misunderstood what that field did. Anyway...
Played around with it a bit more. The display creates now, but all I see is grey (I set the clear color just to make sure that the OpenGL calls were working).
This code is essentially a GLUT equivalent that I'm basing this off of, and it works perfectly. It seems to be a problem with Allegro, or at least a difference in what can be assumed from each library:
==================== EDIT ====================
I did it! All I had to do was add "glMatrixMode (GL_PROJECTION)", which apparently GLUT automatically does and Allegro does not. It's kind of an odd difference, but I have a cube and that's satisfying!!
Thanks for the help,
- L
Allegro by default sets up a 2d "Allegro" matrix, so when you draw with allegro functions, things appear to work with a plain old 2d coordinate space with the top left being 0,0.
Ah.
Just wondering, might it be useful to include something like this in Allegro? I can clean this example up a bit...the resulting cube is pretty cool. It also takes advantage of ALLEGRO_TIMER, which is nice.
Thanks,
- L
If its showing stuff that existing examples don't show, I don't see why not.
Unlike the current OpenGL example, this one actually renders 3-D. I don't know what the Direct3D example shows...
I think it's also just pretty fun to run in the background to make you look cool in front of people looking over your shoulder. =)
I think that under the Allegro.cc terms you guys now own that code or something. I don't exactly know how that provision works, I still own the Copyright, don't I? Anyway, for the wonders of legal clarity, I hereby give the Allegro developers permission to redistribute that code under any license they want, with or without modification. I PROVIDE NOT WARRANTY AT ALL.
Unlike the current OpenGL example, this one actually renders 3-D.
The ex_gldepth example shows interlocking 3D pyramids with textures.
Ah, well then my example doesn't really add anything new. I like the way mine looks better, though. =P
The current example actually has more stuff, too, such as drawing graphical textures onto the polygons.
Thanks,
- L