Ok, so I was working on a map editor, and had it nearing completion when I decided to make the switch from allegro 4 to allegro 5. After much hardship, I finally got it to compile, and it mostly works, except for some major problems. Some of the sprites are black. I am at the moment completely baffled, because I made two scroll bar objects, one vertical, and one horizontal. On these scroll bars, I have a button object with a sprite attached to it for both arrow buttons. The sprite is simply something I created through code. Now the vertical scroll bar looks fine, but the horizontal scroll bar, the right arrow button is black except for the border. No little triangle sprite that coded it to have. The weird part is that the code for the creation of all four directional buttons is virtually identical except for the positions and the relative coords of the triangle on the button. I tried to look for any differences in the code, but to no avail. The only thing that I figured out is that if I reverse the order that I create the left and right buttons, it is the left button that becomes all black rather than the right one. As well the text on the buttons appears as all black, and same with the tiles on the map window.
Here's the horizontal scroll bar code for the creation of the left and right arrow buttons:
And here is the code for drawing the button. There's a lot of stuff in the middle for highlighting/darkening the button depending whether the mouse is hovering over it or it is being clicked. That works just fine and the problem still occurs even if it is commented out.
Also, I attached a screenshot.
]]>Were you able to figure out what was wrong?
I'm interested in this problem and would like to look in to it. Could you provide either all or a piece of the source code that's able to compile so I could try it out?
Just to confirm, there were no "black sprites" when you were using Allegro 4?
]]>Yeah I figured it out. It ended up just being stupid mistakes I made from not being used to Allegro 5. Some of it (the arrow buttons and tiles) were from not setting the target bitmap (I liked the old way better in this case...) in the main function and then calling the clear to colour function. The text on the other buttons was because I forgot to change which font I was loading, and was instead loading an allegro 4 font. I figured that out by messing with the colour the draw text function was passed and realized that I could make the text show up with a pink background if I set it to white. So yeah, all my own stupid mistakes.
EDIT: One question. Am I correct in assuming that allegro 5 coords start at (1,1) instead of (0,0)?
]]>I switched to Allegro 5 only a couple of weeks ago, but from what I can tell everything is still (0, 0) based. Are you experiencing something different?
]]>Coords start at 0/0 - but Allegro 5 uses continuous instead of the A4 pixel coordinates. So 0/0 is not the pixel in the upper left corner of the screen, but the position of the upper left corner of that pixel. Position 0.5/0.5 is the center of that pixel. Position 1/1 is on the intersection of 4 different pixels.
]]>Ok, but then why is it that when I create a bitmap, and then draw a rectangle to it for a border from (0.5,0.5) to (width-.5,height-.5), the border doesn't show up at all on the top or left?
]]>Is it a memory bitmap? OpenGL or D3D? Which platform? Can you give a code example?
]]>ALLEGRO_BITMAP* mapWindow = al_create_bitmap(width,height); al_set_target_bitmap(mapWindow); al_draw_filled_rectangle(.5, .5, width-.5, height-.5, backCol);
EDIT: And that might be the problem... that's not me drawing the border,
]]>The 0.5 offsets are for outlined shapes only. For filled shapes, don't use 0.5 offsets. To understand why, read up on it in the manual, it explains it pretty clearly. I understand you just made a simple mistake, though.
]]>Yes, what Trent says - if you draw a bitmap you usually want it to spawn the complete pixels so you don't want an offset of half a pixel.
]]>If (x+.5,y+.5) is the centre of the pixel, if I make a rounded square border, it should look like this:
oxxxo
xooox
xooox
xooox
oxxxo
Rather, it looks more like:
oxxoo
xooox
xooox
ooooo
oxxoo
With the following code:
al_draw_line(x+1.5, y+.5, x+width-1.5, y+.5, borderCol,1); //Top al_draw_line(x+1.5, y+height-.5, x+width-1.5, y+height-.5, borderCol,1); //Bottom al_draw_line(x+.5, y+height-1.5, x+.5, y+1.5, borderCol,1); //Left al_draw_line(x+width-.5, y+height-1.5, x+width-.5, y+1.5, borderCol,1); //Right
I could easily make it look right, but it doesn't this seem consistent at all.
EDIT: Wow, those diagrams were hard to format correctly...
]]>Look at the pictures here, especially the two al_draw_line calls in the second one: http://www.allegro.cc/manual/5/primitives.html
]]>