Jump to content
  • Advertisement
Sign in to follow this  

Have you guys seen this problem with Allegro before?

This topic is 4815 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a program that loads a small grid and places some tiles in the grid (for a map editor) When the program loads (in fullscreen), I'll often get an image that is all messed up. (messedup.gif) If I run the program in windowed mode, or add a rest() to watch it display slowed down, the program displays everything just fine (normal.gif)). Have you guys seen this before?

Share this post


Link to post
Share on other sites
Advertisement
It's unlikely that this is a problem with Allegro. My first guess is that you are doing something goofy either with setting up fullscreen mode or when you draw the tiles. But all I or anyone else can do is guess unless you show some code to help narrow it down.

Share this post


Link to post
Share on other sites
You are using DirectDraw as the Allegro back-end, and you haven't read the documentation properly.

One of the "features" of DirectDraw is that it sometimes arbitarily throws your surface image data away. Allegro has a callback which will notify your program of this, but you can't do anything about it.

This is NOT a fault of Allegro, but a fact of the way DirectDraw works. Allegro does not automatically double-buffer your screen, so you have to do that yourself.

Bottom line: If you're not redrawing the entire screen each frame (for instance, if you're using dirty rectangles), you need to keep an eye out for this event, and once it is delivered, plan to redraw the entire screen soon.

This is in contrast from the other drivers (like the win32 GDI driver), which automatically save a copy of the "screen" bitmap so that it can be redrawn as necessary transparently to the app.

Mark

Share this post


Link to post
Share on other sites
I've just assumed this was something that I'm not doing properly, so here are my functions (it's the whole source since main() is very short):


#include "allegro.h"

void drawMapGrid(){

line(screen, 0, 0, 340, 0, makecol(255, 255, 255));
for (int x=0; x<=340; x+=17){
line(screen, x, 0, x, 255, makecol(255, 255, 255));
//rest(50);
}

line(screen, 0, 255, 340, 255, makecol(255, 255, 255));
for (int y=0; y<=255; y+=17){
line(screen, 0, y, 340, y, makecol(255, 255, 255));
//rest(50);
}

return;
}
END_OF_FUNCTION(drawMapGrid);

void loadTiles(){

BITMAP *mapTile = load_bitmap("tiles/grass.bmp", 0);

for (int y=1; y<255; y+=17){
for (int x=1; x<340; x+=17){
draw_sprite(screen, mapTile, x, y);
}
//rest(50);
}

return;
}
END_OF_FUNCTION(loadTiles);

int main() {

// initialize allegro
allegro_init();
install_keyboard();
install_timer();
install_mouse();
set_color_depth(16);
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);

// draw the map
drawMapGrid();

// load tiles
loadTiles();

show_mouse(screen);
poll_mouse();

// quit sequence
int doQuit = 0;

while (doQuit == 0) {
readkey();

if(key[KEY_ESC]) {
doQuit=1;
}
}

return 0;
}
END_OF_MAIN();



drawMapGrid() always displays properly. It's my loadTiles() that doesn't display correctly.

Is there anything you can see that I am missing?

Share this post


Link to post
Share on other sites
You don't need to double-buffer, but you do need to be aware of the need to redraw if Allegro tells you that you have to.

Double buffering might be an effective way of doing that, that's all.

DirectDraw will take the surface away (and fill it with black or white when it brings it back, typically). You will have to redraw.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!