Does AllegroGL work in Windows?
James Stanley

I finally got all my stuff installed and compiling.
The game starts but segfaults instantly. I ran it in gdb and there was no stack whatsoever. I put some debugging printf()'s, to see where it got to, and Scite didn't print them, but command.com did...

Eventually I found out that this block is the offending one, so it is presumable a problem with set_gfx_mode():

  if(set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0) != 0) {
    if(set_gfx_mode(GFX_OPENGL_FULLSCREEN, 640, 480, 0, 0) != 0) {
      allegro_message("Video error. Allegro said: %s\n", allegro_error);
      return 1;
    }
  }

So, does AllegroGL work in Windows? Or have I done something wrong?

psycho

OpenGL is compatible with nearly every platform possible ;-)

You must have missed the install_allegro_gl() call, try this code and it should work:

1#include <allegro.h>
2#include <alleggl.h>
3 
4int main() {
5
6 /* Initialize both Allegro and AllegroGL */
7 allegro_init();
8 install_allegro_gl();
9
10 /* Tell Allegro we want to use the keyboard */
11 install_keyboard();
12 
13 /* Suggest a good screen mode for OpenGL */
14 allegro_gl_set(AGL_Z_DEPTH, 8);
15 allegro_gl_set(AGL_COLOR_DEPTH, 16);
16 allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH);
17 
18 /* Set the graphics mode */
19 set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0);
20
21 /* Clear the screen */
22 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
23 
24 /* Set up the view frustum */
25 glMatrixMode(GL_MODELVIEW);
26 glLoadIdentity();
27 glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0);
28 
29 /* Draw a quad using OpenGL */
30 glBegin(GL_QUADS);
31 glColor3ub(255, 255, 255);
32 glVertex3f(-1, -1, -2);
33 glVertex3f( 1, -1, -2);
34 glVertex3f( 1, 1, -2);
35 glVertex3f(-1, 1, -2);
36 glEnd();
37
38 /* Flip the backbuffer on screen */
39 allegro_gl_flip();
40
41 /* Wait for the user to press a key */
42 readkey();
43
44 /* Finished. */
45 return 0;
46}
47END_OF_MAIN();

(copied from http://allegrogl.sourceforge.net/quickstart.txt)

Otherwise, send more code please.

James Stanley

I did install_allegro_gl().
Here's the whole of main:

1 allegro_init();
2 install_allegro_gl();
3
4 set_window_title("Apero by James Stanley");
5
6 allegro_gl_set(AGL_COLOR_DEPTH, 32);
7 allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH);
8 allegro_gl_set(AGL_REQUIRE, AGL_DOUBLEBUFFER);
9
10 set_color_depth(32);
11 
12 if(set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0) != 0) {
13 if(set_gfx_mode(GFX_OPENGL_FULLSCREEN, 640, 480, 0, 0) != 0) {
14 allegro_message("Video error. Allegro said: %s\n", allegro_error);
15 return 1;
16 }
17 }
18
19 opengl_init();
20
21 apero_init();
22
23 main_loop();
24
25 return 0;

EDIT: Removed opengl_init() because the crash is before that.

Milan Mimica

You should remove set_color_depth(32). But I don't think that causes a crash. Can you compile a debug version of the library and find out with gdb where exactly it crashes?

Are you using AllegroGL 0.4.1?
What is your GFX card?
But, in general, yes, AGL works in Windows.

Sirocco

Yeah, it works in windows. Look at the example programs for how to set up a basic OpenGL program. If those run correctly then you're missing a critical call like install_allegro_gl() or something similar.

James Stanley

I put set_color_depth() in because the map loader generates allegro BITMAP's and converts them to OpenGL textures.

I am using AllegroGL version '0.2.5 CVS 20050308', it's the DevPak that I got in Dev-Cpp. I didn't notice it was so old when I installed it. I'll see if I can get a newer version.

Not got a clue about the graphics card, but it's onboard so it's probably i810.

EDIT:
Sirocco, it's not a 'proper' problem with the code, as it compiles and runs fine on FreeBSD and Debian. I just can't make it work in school or on friend's computers.

EDIT2:
Installed AllegroGL 0.4.1. Same problem. Problem might be that it's using the old one. I'll try getting rid of it...

EDIT3:
Finally got it working with -lagl_s. Problem over!

Milan Mimica

Yeah, there were such bugs back in 2005. ::) Always use the latest!
Calling set_color_depth() does nothing! AGL will call it for you in set_gfx_mode() with the color depth it selected.

James Stanley
Milan said:

Always use the latest!

Heh. Sorry. I assumed that, like most repositories, they kept it up to date. Now I realise that with Dev-C++, never assume anything.

Thread #591750. Printed from Allegro.cc