Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 + OpenGL

Credits go to gnolam for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
Allegro 5 + OpenGL
J-Gamer
Member #12,491
January 2011
avatar

I want to learn OpenGL, but all tutorials I find about it on the net use an extra library which I don't want to learn... I have noticed Allegro 5 has the ability to integrate OpenGL, so I wanted to use it.

Now I've made a program that, in my view, should produce a white triangle facing the viewer. But all the program outputs is a black screen...
Here's the code:

#SelectExpand
1#include <allegro5/allegro5.h> 2#include <allegro5/allegro_opengl.h> 3 4#include <cstdio> 5 6 7void init(ALLEGRO_EVENT_QUEUE* &e_queue, int w, int h, int full=0, int opengl=1) 8{ 9 if(full) al_set_new_display_flags(ALLEGRO_FULLSCREEN); 10 if(opengl) al_set_new_display_flags(ALLEGRO_OPENGL); 11 12 ALLEGRO_DISPLAY* display = al_create_display(w,h); 13 if(!display) printf("ERROR INITIALIZING THE DISPLAY AT %i %i!",w,h); 14 15 glEnable(GL_DEPTH_TEST); 16 glEnable(GL_NORMALIZE); 17 18 e_queue = al_create_event_queue(); 19 if(!e_queue) printf("ERROR CREATING EVENT QUEUE!"); 20 21 al_register_event_source(e_queue, al_get_display_event_source(display)); 22 al_register_event_source(e_queue, al_get_keyboard_event_source()); 23} 24 25int install_allegro() 26{ 27 if(!al_init()) 28 { 29 printf("ERROR INITIALIZING ALLEGRO!"); 30 return 0; 31 } 32 if(!al_install_keyboard()) 33 { 34 printf("ERROR INITIALIZING KEYBOARD!"); 35 return 0; 36 } 37 return 1; 38} 39 40void render() 41{ 42 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 43 glMatrixMode(GL_MODELVIEW); 44 glLoadIdentity(); 45 46 47 glBegin(GL_TRIANGLES); 48 49 glColor3f(1.0,1.0,1.0); 50 51 glVertex3f(5.0f,6.0f,10.0f); 52 glVertex3f(8.0f,9.0f,10.0f); 53 glVertex3f(10.0f,25.0f,10.0f); 54 55 glEnd(); 56 al_flip_display(); 57} 58 59int main() 60{ 61 ALLEGRO_EVENT_QUEUE* event_queue = NULL; 62 if(!install_allegro()) return 1; 63 init(event_queue,800,600); 64 65 ALLEGRO_TIMER* fps = al_create_timer(1.0f/25.0f); 66 al_register_event_source(event_queue, al_get_timer_event_source(fps)); 67 68 ALLEGRO_EVENT ev; 69 bool quit = false; 70 bool redraw = false; 71 al_start_timer(fps); 72 while(!quit) 73 { 74 al_wait_for_event(event_queue,&ev); 75 76 if(ev.type==ALLEGRO_EVENT_KEY_DOWN) 77 { 78 if(ev.keyboard.keycode==ALLEGRO_KEY_ESCAPE) quit = true; 79 } 80 if(ev.type==ALLEGRO_EVENT_TIMER) 81 { 82 redraw = true; 83 } 84 85 if(redraw) 86 { 87 render(); 88 } 89 } 90 91 al_destroy_display(al_get_current_display()); 92 al_destroy_event_queue(event_queue); 93 return 0; 94}

I looked at ex_opengl.c(it compiled and ran fine) but it was way too complicated for me to figure out what it did... I just want a single triangle drawn for now.

I ran this trough the debugger and I saw that the al_flip_display call is getting reached. I also tried feeding other coordinates to the glVertex3f calls(including negative z), but for no avail...

Any ideas?

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

gnolam
Member #2,030
March 2002
avatar

  1. You haven't set a projection.
    (e.g. void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);)

  2. You haven't set the viewport: void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

J-Gamer
Member #12,491
January 2011
avatar

Thanks ^^

EDIT:
I tried putting this in render(), but I still get the same output ._.

#SelectExpand
1 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 2 glMatrixMode(GL_PROJECTION); 3 glLoadIdentity(); 4 glViewport(0,0,20,20); 5 glOrtho(0,20,0,20,5,15); 6 7 8 glBegin(GL_TRIANGLES); 9 10 glColor3f(1.0f,1.0f,1.0f); 11 12 glVertex3f(5.0f,6.0f,10.0f); 13 glVertex3f(8.0f,9.0f,10.0f); 14 glVertex3f(10.0f,19.0f,10.0f); 15 16 glEnd(); 17 al_flip_display();

Sorry for me being so n00bish, but I really want to understand how I can make OpenGL work...

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Arthur Kalliokoski
Second in Command
February 2005
avatar

Have you looked at allegro-5blahblah/examples/ex_opengl.c?

They all watch too much MSNBC... they get ideas.

J-Gamer
Member #12,491
January 2011
avatar

Yes I did(see my first post), but I can't really understand what's happening in the drawing function... The OpenGL reference page isn't really helpful at understanding it(WTH are vertical/horizontal clipping panes used in glOrtho???).

Does somebody have some code lying around to just show how you can setup an allegro opengl screen and draw a simple polygon(e.g. a triangle/quad) to it?

EDIT: Am I right that glViewport positions the camera? Or is it's effect the opposite(change the coordinates at which everything is drawn)?

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Arthur Kalliokoski
Second in Command
February 2005
avatar

J-Gamer said:

EDIT: Am I right that glViewport positions the camera? Or is it's effect the opposite(change the coordinates at which everything is drawn)?

glViewport changes how "wide" the scene is, to position the camera you'd do a glTranslate(x,y,z) and glRotatef(x,y,z) or similar (my internets too broken to google properly).

Maybe this would help (uses gluLookAt())

Swiped from glfw demo program.

#SelectExpand
1 // Set viewport 2 glViewport( 0, 0, screen_width, screen_height ); 3 4 // Clear color buffer 5 glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 6 glClear( GL_COLOR_BUFFER_BIT ); 7 8 // Select and setup the projection matrix 9 glMatrixMode( GL_PROJECTION ); 10 glLoadIdentity(); 11 gluPerspective( 65.0f, (GLfloat)screen_width/(GLfloat)screen_height, 1.0f, 12 100.0f ); 13 14 // Select and setup the modelview matrix 15 glMatrixMode( GL_MODELVIEW ); 16 glLoadIdentity(); 17 gluLookAt( 0.0f, 1.0f, 0.0f, // Eye-position 18 0.0f, 20.0f, 0.0f, // View-point 19 0.0f, 0.0f, 1.0f ); // Up-vector 20 21 glTranslatef( 0.0f, 14.0f, 0.0f ); 22 glBegin( GL_TRIANGLES ); 23 glColor3f( 1.0f, 0.0f, 0.0f ); 24 glVertex3f( -5.0f, 0.0f, -4.0f ); 25 glColor3f( 0.0f, 1.0f, 0.0f ); 26 glVertex3f( 5.0f, 0.0f, -4.0f ); 27 glColor3f( 0.0f, 0.0f, 1.0f ); 28 glVertex3f( 0.0f, 0.0f, 6.0f ); 29 glEnd(); 30 31 // Swap buffers 32 al_flip_display();

They all watch too much MSNBC... they get ideas.

Elias
Member #358
May 2000

See here: http://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml

As it says there, it's window coordinates. In your case you want: glViewport(0, 0, 800, 600); (Note that this is the default so you can leave out the call if you want.)

As for glOrtho: http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml

You can't use OpenGL without understanding at least most of that. Your glOrtho call looks fine though.

--
"Either help out or stop whining" - Evert

J-Gamer
Member #12,491
January 2011
avatar

EDIT: It just doesn't work ._. I'm starting to get fired up about this, since this code seems like it should work, but it doesn't... I just want a plain white triangle across my screen. Here's my latest attempt(can someone try and test this to make sure it doesn't have anything to do with my comp?):

#SelectExpand
1#include <allegro5/allegro5.h> 2#include <allegro5/allegro_opengl.h> 3 4#include <cstdio> 5 6 7void init(ALLEGRO_EVENT_QUEUE* &e_queue, int w, int h, int full=0, int opengl=1) 8{ 9 if(full) al_set_new_display_flags(ALLEGRO_FULLSCREEN); 10 if(opengl) al_set_new_display_flags(ALLEGRO_OPENGL); 11 12 ALLEGRO_DISPLAY* display = al_create_display(w,h); 13 if(!display) printf("ERROR INITIALIZING THE DISPLAY AT %i %i!",w,h); 14 15 e_queue = al_create_event_queue(); 16 if(!e_queue) printf("ERROR CREATING EVENT QUEUE!"); 17 18 al_register_event_source(e_queue, al_get_display_event_source(display)); 19 al_register_event_source(e_queue, al_get_keyboard_event_source()); 20} 21 22int install_allegro() 23{ 24 if(!al_init()) 25 { 26 printf("ERROR INITIALIZING ALLEGRO!"); 27 return 0; 28 } 29 if(!al_install_keyboard()) 30 { 31 printf("ERROR INITIALIZING KEYBOARD!"); 32 return 0; 33 } 34 return 1; 35} 36 37void render() 38{ 39 glPushMatrix(); 40 glClear(GL_COLOR_BUFFER_BIT); 41 glMatrixMode(GL_MODELVIEW); 42 glLoadIdentity(); 43 44 45 glBegin(GL_TRIANGLES); 46 47 glColor3f(1.0f,1.0f,1.0f); 48 49 glVertex3f(100.0f,600.0f,0.0f); 50 glVertex3f(800.0f,0.0f,0.0f); 51 glVertex3f(400.0f,300.0f,0.0f); 52 53 glEnd(); 54 glFlush(); 55 glPopMatrix(); 56 al_flip_display(); 57} 58 59void init_opengl() 60{ 61 glEnable(GL_DEPTH_TEST); 62 63 glViewport(0,800,0,600); 64 glMatrixMode(GL_PROJECTION); 65 glOrtho(0,800,0,600,-200,200); 66 glClearColor(0,0,0,1); 67} 68 69int main() 70{ 71 ALLEGRO_EVENT_QUEUE* event_queue = NULL; 72 if(!install_allegro()) return 1; 73 init(event_queue,800,600); 74 init_opengl(); 75 76 ALLEGRO_TIMER* fps = al_create_timer(1.0f/25.0f); 77 al_register_event_source(event_queue, al_get_timer_event_source(fps)); 78 79 ALLEGRO_EVENT ev; 80 bool quit = false; 81 bool redraw = false; 82 al_start_timer(fps); 83 while(!quit) 84 { 85 al_wait_for_event(event_queue,&ev); 86 87 if(ev.type==ALLEGRO_EVENT_KEY_DOWN) 88 { 89 if(ev.keyboard.keycode==ALLEGRO_KEY_ESCAPE) quit = true; 90 } 91 if(ev.type==ALLEGRO_EVENT_TIMER) 92 { 93 redraw = true; 94 } 95 96 if(redraw) 97 { 98 render(); 99 } 100 } 101 102 al_destroy_display(al_get_current_display()); 103 al_destroy_event_queue(event_queue); 104 return 0; 105}

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Trent Gamblin
Member #261
April 2000
avatar

Your viewport is definitely wrong, and I don't think you want your ortho transform like that either. Try this:

    glViewport(0,0,800,600);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,800,600,0,-200,200);
    glClearColor(0,0,0,1);

Elias
Member #358
May 2000

Also, if you keep depth testing enabled, you need to clear the depth buffer.

--
"Either help out or stop whining" - Evert

J-Gamer
Member #12,491
January 2011
avatar

Fixed, but still nothing to see ???

@Elias: Is this done like this?
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
If so, I already did this, but for no avail...

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Trent Gamblin
Member #261
April 2000
avatar

Well after my changes I do see something... not sure it's what you indended but I see a white triangle, thin down the middle of the screen.

J-Gamer
Member #12,491
January 2011
avatar

I don't see it... What coordinates should I give it to let it fill almost the whole/half of the screen? I already tried this:

    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(800.0f,0.0f,0.0f);
    glVertex3f(800.0f,600.0f,0.0f);

But it didn't work out. I thought it would fill up half the screen... what's wrong with my understanding of coordinates?

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Trent Gamblin
Member #261
April 2000
avatar

That should work, providing you don't have face culling on or something like that. And that you clear the depth buffer or turn it off.

J-Gamer
Member #12,491
January 2011
avatar

I haven't called glEnable(GL_CULL_FACE) so I don't think face culling is enabled. I also tried commenting out the call to glEnable(GL_DEPTH_BUFFER) and deleting the glClear(GL_DEPTH_BUFFER_BIT), but again: nothing to be seen ._.

EDIT: wait a minute... I see a small white dot in the upper-left corner of my application, 1 pixel is lit ???

EDIT2: This only happens when I set the coordinates of the last two points to this or greater:

    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(800.0f,0.0f,0.0f);
    glVertex3f(800.0f,600.0f,0.0f);

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Trent Gamblin
Member #261
April 2000
avatar

If you didn't fix your viewport or ortho transform nothing's going to work.

J-Gamer
Member #12,491
January 2011
avatar

I fixed the argument order already...

FIXED: I forgot to put glLoadIdentity() after glMatrixMode(GL_PROJECTION) facepalm, so the matrix was probably filled with garbage ._.

Output:
{"name":"604240","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/0\/606655c858c99c3ba968be97f8840a45.png","w":814,"h":639,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/0\/606655c858c99c3ba968be97f8840a45"}604240

Here's the full code again:

#SelectExpand
1#include <allegro5/allegro5.h> 2#include <allegro5/allegro_opengl.h> 3 4#include <cstdio> 5 6 7void init(ALLEGRO_EVENT_QUEUE* &e_queue, int w, int h, int full=0, int opengl=1) 8{ 9 if(full) al_set_new_display_flags(ALLEGRO_FULLSCREEN); 10 if(opengl) al_set_new_display_flags(ALLEGRO_OPENGL); 11 12 ALLEGRO_DISPLAY* display = al_create_display(w,h); 13 if(!display) printf("ERROR INITIALIZING THE DISPLAY AT %i %i!",w,h); 14 15 e_queue = al_create_event_queue(); 16 if(!e_queue) printf("ERROR CREATING EVENT QUEUE!"); 17 18 al_register_event_source(e_queue, al_get_display_event_source(display)); 19 al_register_event_source(e_queue, al_get_keyboard_event_source()); 20} 21 22int install_allegro() 23{ 24 if(!al_init()) 25 { 26 printf("ERROR INITIALIZING ALLEGRO!"); 27 return 0; 28 } 29 if(!al_install_keyboard()) 30 { 31 printf("ERROR INITIALIZING KEYBOARD!"); 32 return 0; 33 } 34 return 1; 35} 36 37void render() 38{ 39 glPushMatrix(); 40 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 41 glMatrixMode(GL_MODELVIEW); 42 glLoadIdentity(); 43 44 45 glBegin(GL_TRIANGLES); 46 47 glColor3f(1.0f,1.0f,1.0f); 48 49 glVertex3f(0.0f,0.0f,0.0f); 50 glVertex3f(800.0f,0.0f,0.0f); 51 glVertex3f(800.0f,600.0f,0.0f); 52 53 glEnd(); 54 glFlush(); 55 glPopMatrix(); 56 al_flip_display(); 57} 58 59void init_opengl() 60{ 61 glEnable(GL_DEPTH_TEST); 62 63 glViewport(0,0,800,600); 64 glMatrixMode(GL_PROJECTION); 65 glLoadIdentity(); 66 glOrtho(0,800,600,0,-200,200); 67 glClearColor(0,0,0,1); 68} 69 70int main() 71{ 72 ALLEGRO_EVENT_QUEUE* event_queue = NULL; 73 if(!install_allegro()) return 1; 74 init(event_queue,800,600); 75 init_opengl(); 76 77 ALLEGRO_TIMER* fps = al_create_timer(1.0f/25.0f); 78 al_register_event_source(event_queue, al_get_timer_event_source(fps)); 79 80 ALLEGRO_EVENT ev; 81 bool quit = false; 82 bool redraw = false; 83 al_start_timer(fps); 84 while(!quit) 85 { 86 al_wait_for_event(event_queue,&ev); 87 88 if(ev.type==ALLEGRO_EVENT_KEY_DOWN) 89 { 90 if(ev.keyboard.keycode==ALLEGRO_KEY_ESCAPE) quit = true; 91 } 92 if(ev.type==ALLEGRO_EVENT_TIMER) 93 { 94 redraw = true; 95 } 96 97 if(redraw) 98 { 99 render(); 100 } 101 } 102 103 al_destroy_display(al_get_current_display()); 104 al_destroy_event_queue(event_queue); 105 return 0; 106}

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

gnolam
Member #2,030
March 2002
avatar

Now make that triangle properly counter-clockwise. :)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

J-Gamer
Member #12,491
January 2011
avatar

What do you mean with counter-clockwise?

This?
{"name":"604241","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/7\/a70bf49d9c1e63febcd246a9ceecf75a.png","w":814,"h":635,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/7\/a70bf49d9c1e63febcd246a9ceecf75a"}604241

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

gnolam
Member #2,030
March 2002
avatar

I mean defining your vertices in a counter-clockwise rather than clockwise order:
604242
In the picture above, that would be e.g. (A, B, C), instead of (A, C, B).

By convention (inherited from mathematics), a face's vertices are ordered counter-clockwise (you can change this in OpenGL, but don't). This allows you to tell which way a triangle is facing - the (A, B, C) triangle would be facing towards you, while the (A, C, B) triangle would be facing away from you. This allows you to cull the away-facing triangles. Which you want to do, even for trivial projects (there's no additional cost to it, and it cuts the number of triangles you have to render roughly in half). :)

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Jefferson Almeida
Member #12,659
March 2011

Hi... My example of opengl, is simple, but maybe help you in something!

Picture: http://i55.tinypic.com/29yp01t.jpg

A red triangle in the center of the window:

#SelectExpand
1 2#include <iostream> 3#include <stdio.h> 4#include <allegro5/allegro.h> 5#include <allegro5/allegro_opengl.h> 6 7 8ALLEGRO_EVENT_QUEUE *event_queue; 9 10void draw_opengl(void) 11{ 12 // Window background color 13 glClearColor(0, 0, 0, 1); 14 // Clear a window 15 glClear(GL_COLOR_BUFFER_BIT); 16 17 // Initializes coordinate system of projection 18 glMatrixMode(GL_PROJECTION); 19 glLoadIdentity(); 20 // Volume Visualization (xMin, xMax, yMin, yMax, zMin, zMax) 21 glOrtho(-100, 100, -100, 100, -1, 1); 22 23 // Initializes the coordinate system 24 glMatrixMode(GL_MODELVIEW); 25 glLoadIdentity(); 26 27 // Draw a red triangle in the center of the window 28 glColor3f(1, 0, 0); 29 glBegin(GL_TRIANGLES); 30 glVertex2f(-50, -50); 31 glVertex2f( 0, 50); 32 glVertex2f( 50, -50); 33 glEnd(); 34} 35 36static void main_loop(void) 37{ 38 ALLEGRO_EVENT ev; 39 40 while (true) { 41 if (al_event_queue_is_empty(event_queue)) { 42 draw_opengl(); 43 al_flip_display(); 44 } 45 al_wait_for_event(event_queue, &ev); 46 switch (ev.type) 47 { 48 case ALLEGRO_EVENT_DISPLAY_CLOSE: 49 return; 50 break; 51 case ALLEGRO_EVENT_KEY_DOWN: 52 if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) 53 return; 54 break; 55 } 56 } 57} 58 59int main(void) 60{ 61 al_init(); 62 63 al_set_new_display_flags(ALLEGRO_OPENGL); 64 65 ALLEGRO_DISPLAY *display = al_create_display(500, 500); 66 67 if ( !al_install_keyboard() ) { 68 fprintf(stderr, "Failed to initialize Keyboard!\n"); 69 return 1; 70 } 71 event_queue = al_create_event_queue(); 72 if (event_queue==NULL) { 73 return 1; 74 } 75 al_register_event_source(event_queue, al_get_keyboard_event_source()); 76 al_register_event_source(event_queue, al_get_display_event_source(display)); 77 78 main_loop(); 79 80 return 0; 81}

J-Gamer
Member #12,491
January 2011
avatar

@gnolam: understood :)
@JA: I already made a program that draws a triangle... I just had some problems setting up OpenGL

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Andynonomous
Member #12,867
May 2011

Quick question about OpenGL in Allegro. Can you combine drawing from both libraries. Like say I'm using allegro bitmaps to make my 2d space game, can I use OpenGL just for lighting effects. Or say use 2d bitmaps for everything in my game except perhaps a sun which I'd draw using OpenGL. Can you combine this way?

J-Gamer
Member #12,491
January 2011
avatar

You can AFAIK... But I don't think the lighting will have an effect on the 2d bitmaps drawn with allegro...

EDIT: I don't seem to get it to work... I put al_draw_rectangle(300,200,400,250,al_map_rgb(255,255,255)); both in front and after the first/last openGL call and before al_flip_display(); but it doesn't show anything ._.(my background is 0,0,0 and the window is 800x600)

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

Elias
Member #358
May 2000

If you modify the matrices you need to store them first and then restore again before calling Allegro commands. Same for any other OpenGL state. If you do that it will work.

--
"Either help out or stop whining" - Evert

 1   2 


Go to: