Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Rotating 3d cube using allegro 5

This thread is locked; no one can reply to it. rss feed Print
Rotating 3d cube using allegro 5
Scooter
Member #16,799
January 2018

Hi guys:
A few days ago I wrote a program to rotate a line 360 degrees! I decided I would
carry it a little further and wrote a program to rotate a square 360 degrees! Now
I want to go even further and see if I can write one to rotate a 3d cube. Well, to
put it simple, I can't! I have been looking at the transformation commands in Allegro 5 and I can't go anywhere with them! I can define my points, but that is as far as I can go with it. If someone has the time, I would appreciate seeing what would be involved in doing this! This may be more than I can handle, but I would like to give it a try! Thanks!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Checklist :

1. Coordinates of cube vertices in 3D space
2. 3D projection matrix set up properly along with the view matrix
3. Draw lines, triangles, or quads
4. Transform coordinates using matrices and the view matrix
5. Texture your cube
6. Lighting, etc... other hard stuff

Scooter
Member #16,799
January 2018

Hi Edgar:
Hope all is well! I believe it is more than I can handle!
Something I thought would be neat to try, but is way over my head!
I don't think I will even attempt it! I better stick to the easy stuff!
Thanks and have a great day!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Hi Edgar:
I have been working for the last few days trying to solve it!
Finally I just sent it all to the trash! I considered it a complete
waste of time! Maybe in the future I will give it another try!

Neil Roy
Member #2,229
April 2002
avatar

I recommend searching online for OpenGL tutorials. Youtube is good as well as several websites. You can do OpenGL in Allegro as well once set up right.

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I spent a good part of today making a (mostly) half baked example demo of a textured cube for you. Included below is a zip file of all the source and a static win32 binary as well as the font I used.

Cube.zip

{"name":"611351","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/7\/77b00861336114a1a59b69162b82ad04.png","w":802,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/7\/77b00861336114a1a59b69162b82ad04"}611351

Press left and right to rotate around the cube and press up and down to change your ascension. Equals and Minus move you in or out.

There are still some problems with it. The cube is supposed to be outlined in white but thats not working. And there's some text that's not drawing anymore, even though it used to and even though I reset the transformations and the letters are sideways don't know what caused that.

I'm sure you're going to have a bunch of questions, but that's okay, ask away. I really want you to try this out, I know you're up to it.

Scooter
Member #16,799
January 2018

Good morning Edgar:
Thanks for doing this for me! Its GREAT!!
I tried compiling the SpinningCubeMain.cpp using my Linux
machine and received the following error: undefined reference
to symbol (Gl_DepthFunc). I did some research and thinking my
openGL needed to be updated. I found that the function is included
in both 3 and 4 versions. I don't know why Code:Blocks is not picking
it up. If you think Linux may be the problem, I will have to load
Allegro and openGL on my XP machine to be able to try out your code!
I also thought that I would try the g++ compiler. It is loaded on my
machine but Code:Blocks is not picking that up.
OH, my problems continue! Hope your day is going fine!
Thanks for your time! I need to quit sitting around and thinking
things up! Talk later my friend!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

You need to link to OpenGL - "-lopengl32 -lglu32" .

I'll post better instructions soon. I'm on my phone

EDIT
You don't need to update OpenGL, just link to it. It should be called opengl32.lib or libopengl32.a depending on your machine and your compiler.

I made some updates on the cube demo. The text is back, the textures are right side up, and I added in axes and edges (the right color this time).

Cube.zip

{"name":"611352","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/7\/270dfbc1e04b3281211ec2ef45d3f3e6.png","w":802,"h":633,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/7\/270dfbc1e04b3281211ec2ef45d3f3e6"}611352

Let me know if you have trouble building it, or running it.

Scooter
Member #16,799
January 2018

Hi Edgar:
I am running Code:Blocks on Ubuntu. I have been trying to find
where they put the Opengl library! All my libraries end in .so.
They are usually in /usr/lib but I can't find it! I will continue
to see what I can come up with. If I knew exactly what it was called,
I could use g++ at the command line. This is getting very interesting!
I tried to run the EXE file on XP, but there was a problem with msvcrt.dll.
Windows reported: The procedure entry point _time32 could not be located
in the dynamic link library msvcrt.dll, whatever that means. I have had
some luck with GLUT, but I have to use the command line to get anything
to work! Code:Blocks kicks out errors about not finding functions!
Hope all is well with you!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter said:

I am running Code:Blocks on Ubuntu. I have been trying to find
where they put the Opengl library! All my libraries end in .so.

On Ubuntu, you need to install the Mesa GL development packages.

OpenGL (libgl1-mesa-dev, libglu-dev) - Devel libs for OpenGL

Note, this one may overwrite some files from your graphics drivers if you installed 3rd party binary drivers (ie: fglrx or nvidias binaries)
If you experience problems, (ie: OpenGL performance is TERRIBLE) you may want to reinstall your graphics drivers.

So your commands would be :

sudo apt-get install libgl1-mesa-dev libglu-dev

How did you install Allegro? Where did you get it from?

EDIT
Also, please post your errors. Otherwise we can't help fix them.

Scooter
Member #16,799
January 2018

Hi Edgar:
In order to install allegro I could have used apt-get install or
went through Synaptic Package Manager.If it was a .deb package I would
have used GDebi Package Installer.
All of my libraries were found in /usr/lib/i386-linux-gnu. Then I loaded
Code:Blocks, went to Settings, Compiler, Linker Settings and typed the
libraries under Linker libraries. Everything worked fine. This morning I
also typed in the libraries for GL, GLU and GLUT. Now all that is working.
When I try to install Opengl, I get the message that I already have the
latest version installed. If I continue to have problems, I will do as you
say. But since you say I might have problems, I will backup my complete
system before I do it. Also, since GLUT calls Opengl functions, I would
believe that Opengl is fine, I just can't find it. This is very interesting
to say the least. On another note: since GLUT will do all the graphics, do
I still need to use Allegro? Just a thought. Have a great day!

Before I closed, I wanted to check to see if what you said was loaded:
libgl1-mesa-dev version 10.1.3 is loaded
libglu1-dev version 9.0.0-2 is loaded

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

If you're using CodeBlocks, and gcc, all you should need to do is link to OpenGL by using "-lopengl32" and "-lglu32" on your command line for the linking options.

You say it's installed already, so linking should just work.

GLUT is an alternative to Allegro, sure, but I think Allegro can do far more for you than GLUT can. Sure, GLUT is nice for simple examples, but beyond that it falls a little short. I use FreeGLUT from time to time, but not so much lately. Allegro does everything I need it to.

Neil Roy
Member #2,229
April 2002
avatar

Given the choice, Allegro is a FAR better one over GLUT. GLUT is very limited. You're better off picking the library you wish to use to make your game with and learning with it, like Allegro.

In the end, once your library like GLUT or Allegro sets up the OpenGL context, they don't have much more to do with it. But they can give you more or less options you will need for a game. And Allegro is very nice for cross platform development. Partnered with OpenGL they make a great pair.

---
“I love you too.” - last words of Wanda Roy

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Hi Edgar:
I am COMPLETELY LOST! I have no idea what to do now!
I am going to have to do more studying and try to figure
this thing out! There seems to be much I know nothing about!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Hi Edgar:
I am finally getting something to happen using GLUT. I never
found where the library for Opengl was located, but Glut knows
where it is because my very simple programs run fine. Also, as
far as I can determine my graphics card only supports version
2.1 of Opengl. I think they have version 3 or maybe 4 now. This
may limit me as to what I can do, but it will be way in the future
before I need to worry about that. Thanks for all you do on this
site! You seem to have it all figured out and that's a good thing!
Hope all is well with you!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Scooter
Member #16,799
January 2018

Edgar:
I already have those loaded including glut.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: