Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Allegro 4 / AllegroGL - can't change gfx mode

Credits go to DanielH, Edgar Reynaldo, and MikiZX for helping out!
This thread is locked; no one can reply to it. rss feed Print
Allegro 4 / AllegroGL - can't change gfx mode
Andrew Gillett
Member #15,868
January 2015

I can't reply to my previous thread ("Allegro 4 game - Steam overlay") as I was the last poster on it, and the forum software won't allow two posts in a row from the same person.

I got my game working, using AllegroGL to copy the back buffer to the screen - but I can't change video mode. Doing this in windowed results in a transparent window (see attachment), in fullscreen I get a black screen. Also the music stops playing, although that is easily dealt with.

Fullscreen at desktop resolution (1080p) always results in a black screen, even if that's the starting resolution.

If I change back to the original screen resolution, the game continues as normal.

I'm guessing this is a case of AllegroGL being partly unfinished (as I found out after hours of trying to work out why stretch_blit didn't work - was never implemented) and not having had the same level of testing as Allegro as a whole.

DanielH
Member #934
January 2001
avatar

You can edit your last post and put something like

*** UPDATE ***

blah, blah

But great that you got it working.

Andrew Gillett
Member #15,868
January 2015

Well, it works in that I can run it - but I can't release my game without the ability to change resolution or run at desktop resolution.

MikiZX
Member #17,092
June 2019

Just few ideas to try (kind of blackbox testing):
Does the resolution change fail even if you are switching from 640x480 to 800x600 and back (windowed-fullscreen-windowed and windowed-windowed-windowed mode)?
Re. FullHD, likely not the case though possibly your gfx card cannot (or its drivers) setup an openGL texture that is 2048x2048 in size?
One test I would try is running the game in 512x512 mode (windowed) and change to 1024x1024 (windowed) and see how that behaves.
Also, possibly you need to (at resolution change) shutdown Allegro and re-initialize it.
Finally, how do you copy the backbuffer to the screen (which commands do you use to actually do the copy)?

EDIT: Not sure if this is a valid suggestion: https://github.com/NewCreature/Allegro-Legacy

Andrew Gillett
Member #15,868
January 2015

I use allegro_gl_make_texture_ex to turn the back buffer into a texture, then draw a single quad.

640x480 to 800x600 and back doesn't work either (or 512/1024).

In 1080p fullscreen, the game is still running, I just can't see anything. allegro_gl_make_texture_ex does not produce an error code.

I will look into Allegro-Legacy next week.

GLuint tex = allegro_gl_make_texture_ex(0, active_page, GL_RGB8);
if (tex == 0)
	end_it_all("Error: allegro_gl_make_texture_ex failed. Please report this error to psector@arganoid.com, or try"
		" disabling OpenGL rendering in AppData\\psector\\psector.cfg");

glBindTexture(GL_TEXTURE_2D, tex);
		
glClearColor(1.0f, 0.0f, 0.0f, 1.f);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);

glTexCoord2f(0, 1);
glVertex2f(-1, -1);

glTexCoord2f(1, 1);
glVertex2f(1, -1);

glTexCoord2f(1, 0);
glVertex2f(1, 1);

glTexCoord2f(0, 0);
glVertex2f(-1, 1);

glEnd();

allegro_gl_flip();

GLuint textures[] = { tex };
glDeleteTextures(1, textures);

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I may not be correct, but I don't think you need to make the backbuffer a texture. You should be able to draw to it normally, with OpenGL, or Allegro.

Also, I have had problems changing resolutions with Allegro 4 before. I have a workaround I use. Set gfx_mode to GFX_TEXT, message a window 'changing to x resolution', and then change the gfx mode to your desired mode.

MikiZX
Member #17,092
June 2019

Your source looks OK to me - which now that I think again it should since it works before the resolution change. Possibly try adding glClear command before drawing the quad and clear both color and depth? Also, possibly allegro_error can provide you with more details:

https://www.allegro.cc/manual/4/api/using-allegro/allegro_error

Also, if there is 'allegro.log' file in your app directory that might contain more details (though that might only appear with debug version of the library).

Sorry I can't help in a better way.

Andrew Gillett
Member #15,868
January 2015

Problem solved: I had a piece of code which asked the user to confirm the resolution change by pressing Y, or cancel it with ESC. This worked by drawing directly to screen, and then waited for a key to be pressed - it did not call my usual screen swap function. Without a call to allegro_gl_flip, the window would remain transparent. Because the message wasn't being displayed, I forgot that the key to confirm the new resolution was Y and not Enter.

The issue with running at 1080p was also an error my code. Previously I would use stretch_blit (not supported in AllegroGL) to copy the back buffer to the screen, but in the special case where the back buffer and screen with the same size (which in practice was only on the main menu when running at 1080p), I would do a simple blit instead. This got messed up in the transition to AllegroGL. After fixing this, it turns out that using blit in this case is actually slower than turning the back buffer into a texture and drawing a quad.

There is an issue running at desktop resolution in a window - the top of the game screen is cut off behind the window's top bar. Perhaps a window bigger than desktop resolution (when the borders are taken into account) can't be created? It's not a big problem as standard Allegro 4 doesn't allow desktop resolution windows either, at least in my experience. So the game already prevents this.

Go to: