Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » A5 glCreateShaderObject/program crash? Is glewInit() needed?

This thread is locked; no one can reply to it. rss feed Print
A5 glCreateShaderObject/program crash? Is glewInit() needed?
Predator106
Member #14,791
December 2012

I'm trying to get my code that uses opengl and allegro to work..

I was following the example (ex_opengl_pixel_shader), and right after it makes the display, it does some shader stuff.

To make it not crash, I can call glewInit(), but is that necessary or valid? I have a feeling it'd screw with all sorts of things.

But when I try to use glewInit(), I cannot for the life of me, pass a valid sampler2d..but that issue is for another thread, i think.

#SelectExpand
1void Game::init() 2{ 3 uint32_t version = al_get_allegro_version(); 4 int major = version >> 24; 5 int minor = (version >> 16) & 255; 6 int revision = (version >> 8) & 255; 7 int release = version & 255; 8 Debug::log(Debug::Area::System) << "Using allegro version: " << major << "." << minor << "." << revision << "." << release; 9 10 Debug::fatal(al_init(), Debug::Area::System, "Failure to init allegro"); 11 12 al_init_font_addon(); 13// Debug::fatal(al_init_acodec_addon(), Debug::Area::System, "Failure to init acodec addon"); 14////FIXME: Debug::fatal(al_init_native_dialog_addon(), Debug::Area::System, "Failure to init native dialog addon"); 15// Debug::fatal(al_init_primitives_addon(), Debug::Area::System, "Failure to init primitives addon"); 16// Debug::fatal(al_init_ttf_addon(), Debug::Area::System, "Failure to init ttf addon"); 17// Debug::fatal(al_init_image_addon(), Debug::Area::System, "Failure to init image addon"); 18// Debug::fatal(al_install_keyboard(), Debug::Area::System, "Failure to install keyboard"); 19// Debug::fatal(al_install_mouse(), Debug::Area::System, "Failure to install mouse"); 20// 21 al_set_new_display_flags( ALLEGRO_OPENGL); 22// al_set_new_display_option( ALLEGRO_VSYNC, 2, ALLEGRO_REQUIRE ); 23 24 m_display = al_create_display(SCREEN_W, SCREEN_H); 25 Debug::fatal(m_display, Debug::Area::Graphics, "display creation failed"); 26 27//FIXME: needed? glewInit(); 28 29 if (!al_have_opengl_extension("GL_EXT_framebuffer_object") 30 && !al_have_opengl_extension("GL_ARB_fragment_shader")) { 31 Debug::fatal(true, Debug::Area::Graphics, ("Fragment shaders not supported.\n")); 32 } 33 34 35 glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);

Kris Asick
Member #1,424
July 2001

I don't quite understand the question you're asking, but as far as using OpenGL and Allegro code together, Allegro will handle everything OpenGL needs done on its own up to the point where you need to take control of OpenGL yourself. At that point, you simply take over for as long as you need, then just let Allegro continue doing its thing. In fact, you can mix OpenGL and Allegro calls together, just keep a couple things in mind:

1. You need to use al_get_opengl_texture() in order to access the OpenGL texture IDs of your ALLEGRO_BITMAP objects.

2. ex_opengl_pixel_shader() doesn't actually do everything perfectly. It makes a couple mistakes yet still works anyways because of the state-machine nature of OpenGL. Here's an example of the code I wrote for my current game project in order to load a particular shader program into video memory, turn it on, and unload it when I'm done with it.

For reference:

  • "VBlur1024" and "VBlur1024_shader" are of type GLhandleARB

  • "VBlur1024_program" and "VBlur1024_program_len" refer to the actual shader code and the number of lines in it

  • "source1" is the name of my sampler2D in my actual shader code

#SelectExpand
1void GFrags_Load_VBlur1024 (void) 2{ 3 if (VBlur1024_loaded) return; 4 VBlur1024_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); 5 glShaderSourceARB(VBlur1024_shader,VBlur1024_program_len,VBlur1024_program,NULL); 6 glCompileShaderARB(VBlur1024_shader); 7 VBlur1024 = glCreateProgramObjectARB(); 8 glAttachObjectARB(VBlur1024,VBlur1024_shader); 9 glLinkProgramARB(VBlur1024); 10 VBlur1024_loaded = true; 11} 12 13void GFrags_Use_VBlur1024 (GLuint source_texture) 14{ 15 GLint loc; 16 if (!VBlur1024_loaded) return; 17 glUseProgramObjectARB(VBlur1024); 18 glActiveTexture(GL_TEXTURE0); 19 glBindTexture(GL_TEXTURE_2D,source_texture); 20 loc = glGetUniformLocationARB(VBlur1024,"source1"); 21 glUniform1iARB(loc,0); 22} 23 24void GFrags_Unload_VBlur1024 (void) 25{ 26 if (!VBlur1024_loaded) return; 27 glDetachObjectARB(VBlur1024, VBlur1024_shader); 28 glDeleteObjectARB(VBlur1024_shader); 29 VBlur1024_loaded = false; 30}

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Predator106
Member #14,791
December 2012

You did answer part of my question, but for some reason I can't run any GL commands without crashing on them, without running glewInit() after I make a display. I don't even know if running glewInit() is compatible with allegro...

I'm using this, as well..

    al_set_new_display_flags( ALLEGRO_OPENGL | ALLEGRO_OPENGL_FORWARD_COMPATIBLE);

and adding ALLEGRO_OPENGL_3_0 to it results in X saying error, failed request: GLXBadFBConfig...and the application locking up there...

Kris Asick
Member #1,424
July 2001

ALLEGRO_OPENGL_FORWARD_COMPATIBLE is meant to prevent the use of depreciated functions and furthermore, Allegro graphical functions cannot properly be used beside OpenGL calls while using this flag. (At least, as far as the manual is concerned.)

Try removing this flag.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Go to: