Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Rendering A Hot Air Balloon

This thread is locked; no one can reply to it. rss feed Print
Rendering A Hot Air Balloon
Scooter
Member #16,799
January 2018

Hi all:

I had an idea the other day: make a hot air balloon

using allegro and opengl. Do you think this would be

a project a newbie could accomplish? If so, where would

one begin? I have had to give up on many things because

it got too difficult for me! This would be great if it

could be done!

Thanks for your time.

bamccaig
Member #7,536
July 2006
avatar

Set the bar low to start. A hot air balloon could be as simple as a circle with a square beneath it, or a sphere and a cube if 3D.

Note: Allegro doesn't really help you drawing 3D things. You need to do that with GL directly. Allegro will just initialize things for you I think.

After you've got a very simple program working you can expand upon it to make it better, piece by piece. If you aim too high you won't get anything done.

Scooter
Member #16,799
January 2018

Hi bamccaig:

Great idea! If I start with a sphere, bring the bottom of the

sphere down, narrow it a bit I would have the shape I need.

Is there a way to do such a thing in opengl? Just a thought.

Thanks

bamccaig
Member #7,536
July 2006
avatar

I'm afraid OpenGL is far too complicated to learn it from questions and answers on a messaging board. If you don't know it yet you're going to have to learn it first. Put the hot air balloon idea on a shelf, and start by completing an OpenGL tutorial or two. Once you've got a simple program running you can try Googling for things that you think you'll need for the hot air balloon, and try to figure out how to do it. If you have trouble getting something to work you can post here, but don't expect us to do your homework for you. That's not how the Internet works. :) I can't help anyway because I myself haven't gone past the tutorial step.

Scooter
Member #16,799
January 2018

Hi bamccaig:

Sorry, didn't mean to upset you!

Have a great day!

bamccaig
Member #7,536
July 2006
avatar

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Step 1) Decide the technical requirements of what you want to do.
Step 2) Decide what is the best way to accomplish that
Step 3) Implement a very basic version to start
Step 4) Improve
Step 5) Repeat step 4
Step 6) Decide if you're satisfied with where you're at.
Step 6a) Go back to 1
Step 7) $PROFIT$

For instance, here's a hot air balloon I drew by accident. Allegro is more than capable of drawing a balloon as a polygon, a set of lines, etc... You don't specifically need to know OpenGL to do it.

http://members.allegro.cc/EdgarReynaldo/previews/Spiraloid/Balloon1.html

{"name":"Balloon1.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/c\/dca6d415a73ea6eb425fd585553435af.png","w":1024,"h":768,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/c\/dca6d415a73ea6eb425fd585553435af"}Balloon1.png

EDIT
Technically you can think of a balloon as a series of discs layered together.

Once you have that, you can try to texture it.

Scooter
Member #16,799
January 2018

Hi Edgar:

Thanks for the reply. It has been awhile, hope all is well!

I have downloaded 2 files: balloon.jpg and section.png. The

balloon file will show you what I am trying to duplicate. There

are 10 sections to the balloon. The section file shows one

of the 10 sections without the birds. My problem is the section

has to be fitted to the balloon shape. That is my problem. What

is the best way to do this? If you have any questions let me know.

Thanks!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Are you planning on a 2D balloon or a 3D one?

You need the vertices, and the texture coordinates.

From something like an .obj or some kind of model file.

Then you can draw with allegro or opengl.

Scooter
Member #16,799
January 2018

Hi Edgar:

Oh, it must be 3D in opengl! As far as the .obj file: do I need to

do the balloon in Blender and then import to opengl? I hope not!

Thanks!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Make the strips horizontal. Vertical will only give you pain. Break them up into a band. Take a disc and make a bracelet. The outside of the bracelet is the band which you render in opengl. You still don't need OpenGL to do this, as allegro can do it for you.

al_draw_prim

hint
It can be done by hand with a little radial trigonometry in 3D.

Align it down the axis, and every band is just a circle of different radius connected to to the previous and next strip.

MikiZX
Member #17,092
June 2019

I've been playing with the problem of creating a hot air balloon in code and.. well.. maybe it helps:
(done using gluCylinder and gluSphere)

#SelectExpand
1#include <stdio.h> 2#include <math.h> 3#include <allegro5/allegro.h> 4#include "allegro5/allegro_primitives.h" 5#include <allegro5/allegro_opengl.h> 6#include <GL/glu.h> 7 8 9const float FPS = 60; 10 11ALLEGRO_DISPLAY *display = NULL; 12ALLEGRO_EVENT_QUEUE *event_queue = NULL; 13ALLEGRO_TIMER *timer1 = NULL; 14 15bool redraw = true; 16 17double lightangle = 0.0; 18GLUquadricObj *quadric = NULL; 19 20// isolating cleanup code in a single function because we use this code many times 21// doing this will keep the rest of the source code easier to read 22void close_and_exit() 23{ 24 if (quadric) gluDeleteQuadric(quadric); 25 if (timer1) al_destroy_timer(timer1); 26 if (display) al_destroy_display(display); 27 if (event_queue) al_destroy_event_queue(event_queue); 28 al_uninstall_system(); 29 exit(0); 30} 31 32// the program execution starts here with 'main' function 33int main(int argc, char **argv){ 34 35 // here we initialize different parts of Allegro 36 if(!al_init()) { 37 fprintf(stderr, "failed to initialize allegro!\n"); 38 return -1; 39 } 40 41 al_init_primitives_addon(); 42 al_set_new_display_option(ALLEGRO_DEPTH_SIZE , ALLEGRO_DONTCARE , 16); 43 al_set_new_display_flags(ALLEGRO_OPENGL ); 44 display = al_create_display(640, 480); 45 if(!display) { 46 fprintf(stderr, "failed to create display!\n"); 47 close_and_exit(); 48 } 49 50 if (!al_install_keyboard()) 51 { 52 fprintf(stderr, "Error installing keyboard.\n"); 53 close_and_exit(); 54 } 55 56 event_queue = al_create_event_queue(); 57 if(!event_queue) { 58 fprintf(stderr, "failed to create event_queue!\n"); 59 close_and_exit(); 60 } 61 62 timer1 = al_create_timer(1.0 / FPS); 63 if(!timer1) { 64 fprintf(stderr, "failed to create timer!\n"); 65 close_and_exit(); 66 } 67 68 al_register_event_source(event_queue, al_get_keyboard_event_source()); 69 70 al_register_event_source(event_queue, al_get_display_event_source(display)); 71 72 al_register_event_source(event_queue, al_get_timer_event_source(timer1)); 73 74 al_start_timer(timer1); 75 76glEnable(GL_DEPTH_TEST); 77glDisable(GL_CULL_FACE); 78glEnable(GL_LIGHTING); 79quadric = gluNewQuadric(); 80 while(1) 81 { 82 ALLEGRO_EVENT ev; 83 al_wait_for_event(event_queue, &ev); 84 85 if(ev.type == ALLEGRO_EVENT_TIMER) { 86 redraw = true; 87 } 88 89 if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { 90 91 if (ev.keyboard.keycode==ALLEGRO_KEY_ESCAPE) 92 close_and_exit(); 93 } 94 95 96 if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 97 break; 98 } 99 100 if(redraw && al_is_event_queue_empty(event_queue)) 101 { 102 redraw = false; 103 al_set_target_backbuffer(display); 104 al_clear_to_color(al_map_rgb(0,50,140)); 105 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 106 glMatrixMode(GL_PROJECTION); 107 glLoadIdentity(); 108 gluPerspective(90.0, (GLdouble)640.0 / (GLdouble)480.0, 1.0, 2000.0); 109 110 glMatrixMode(GL_MODELVIEW); 111 glLoadIdentity(); 112 gluLookAt(0.0f, 0.0f, -100.0f, 0.0f, 0.0f, 1.0f, 0.0, 1.0f, 0.0f); 113 114 GLfloat light0_pos[] = {50.0, 50.0, -50.0, 1.0}; 115 GLfloat light0_color[] = {0.01, 0.01, 0.01, 0.0}; 116 GLfloat light1_pos[] = {10.0, 35.0, -10.0, 1.0}; 117 GLfloat light1_color[] = {1.0, 0.80, 0.65, 0.0}; 118 light1_pos[0]=cos(lightangle/10.0)*4000.0; 119 light1_pos[2]=sin(lightangle/10.0)*4000.0; 120 lightangle+=0.01; 121 glLightfv( GL_LIGHT0,GL_POSITION,light0_pos); 122 glLightfv( GL_LIGHT0,GL_DIFFUSE,light1_color); 123 glLightfv( GL_LIGHT0,GL_AMBIENT,light0_color); 124 glLightfv( GL_LIGHT1,GL_POSITION,light1_pos); 125 glLightfv( GL_LIGHT1,GL_DIFFUSE,light1_color); 126 glLightfv( GL_LIGHT1,GL_AMBIENT,light1_color); 127 glEnable(GL_LIGHT0); 128 glEnable(GL_LIGHT1); 129 130 glTranslatef(0,30+cos(lightangle/10.0)*cos(lightangle/5.0)*20.0,0); 131 glRotatef(cos(lightangle)*5.0,0,2.0,0); 132 glRotatef(cos(lightangle*2.0),0,0,2.0); 133 glColor3f(1,1,0); 134 gluQuadricTexture(quadric, GL_FALSE); // halt texture coordinate generation 135 gluQuadricDrawStyle(quadric, GLU_FILL ); 136 gluQuadricDrawStyle(quadric, GLU_OUTSIDE ); 137 gluQuadricNormals(quadric, GL_SMOOTH); 138 gluSphere (quadric, 30.0f, 18, 18); // radius, slices, stacks 139 glRotatef(90,1,0,0); 140 glColor3f(1,1,0); 141 gluQuadricDrawStyle(quadric, GLU_LINE); 142 gluCylinder(quadric,30,10,50,12,2); 143 glTranslatef(0,0,50); 144 gluQuadricDrawStyle(quadric, GLU_FILL); 145 gluCylinder(quadric,10,8,10,12,12); 146 147 al_flip_display(); 148 } 149 } 150 close_and_exit(); 151}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

MikiZX
Member #17,092
June 2019

Oh.. ok.. :)
{"name":"612522","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/3\/7383936d0090dfd1c00ea7c2d50fce70.png","w":606,"h":463,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/3\/7383936d0090dfd1c00ea7c2d50fce70"}612522

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

pmprog
Member #11,579
January 2010
avatar

@MikiZX: Out of curiousity, is there any reason you didn't use the Allegro 3D transform functions and primitive rendering?

MikiZX
Member #17,092
June 2019

Hm.. honestly said I was 'thinking in OpenGL' at the time and did not even think of Allegro5's transforms - I was just happy it worked.
Also, initialization of OpenGl and the part that sets the projection matrix come from posts posted on this forum few years ago by Edgar.
Though I am likely wrong, now that I think about it I think Allegro5 transforms are 2d oriented (Edgar is likely to correct or confirm this)? I think with Allegro5 transforms you always get a 2d/Ortho projection... ?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

There are 2D and 3D transformations. The 2D transformations use 3D under the hood.

The projection matrix is whatever you set it to. It's all 3D under the hood. Ortho just gives you a flat space in a certain plane to work with.

Go to: