Faint Output When Writing To Gp2x Frame Buffer Device (/dev/fb0)


paul_nicholls

Still Fresh
Joined
Nov 23, 2006
Messages
42
Hi all,
I am experimenting (using freepascal) with writing to the gp2x frame buffer (/dev/fb0) directly to see if I can speed up some graphics I was doing.

I am opening up the frame buffer device using the Open() function:

CODE
fb := Open('/dev/fb0', O_RDWR);


I am then mapping memory like so (assuming 320 by 240, 16bit):

CODE
FMemData := MMap(Nil, 320 * 240 *2, PROT_WRITE, MAP_SHARED, fb,0);


When I draw pixels, etc, I write to the mapped memory by taking the FMemData pointer, offsetting by
CODE
(x * 2) + 320 * 2 * y
and storing the 565 formatted pixel at that location.

This works, but I can barely see the result...the output is very, very faint...

Can anyone think of why the output would be so faint?

As I am not using SDL to create a window and draw the graphics, could perhaps the backlight be off when doing this?

cheers,
Paul.
 
The backlight is turned on by the bootloader (before linux is loaded), and nothing turns it off, so I would be very doubtful that it would be off when your program executes.

Try doing an entire screen instead of a single pixel.
 
Squidge said:
The backlight is turned on by the bootloader (before linux is loaded), and nothing turns it off, so I would be very doubtful that it would be off when your program executes.

Try doing an entire screen instead of a single pixel.
I was only guessing about the backlight :)

:D The code I posted was just showing how I do it, I am really drawing random lines on the screen (same locations each run though) and I can barely see them :(

I am calling SDL_Init() prior to drawing the output to the framebuffer so I can use SDL to get keys, etc.
Could this be interfering with the graphics output?

I am not calling SDL_SetVideoMode() and creating a window at all though.
cheers,
Paul.
 
Last edited by a moderator:
when you say you can barely see it, you mean that they're all close to black, or to white? maybe the code for picking the color of the lines isn't behaving like you want it to...maybe try just drawing a single color or something. maybe you've already done this though.
 
rokdcasbah said:
when you say you can barely see it, you mean that they're all close to black, or to white? maybe the code for picking the color of the lines isn't behaving like you want it to...maybe try just drawing a single color or something. maybe you've already done this though.
The output is really dark...if I peer closely at the screen it seems to have drawn the lines with the random colors but it is hard to tell as the lines are very faint.

I am going to have to try drawing filled rectangles or similar so I can perhaps see better what is going on.

cheers,
Paul.
 
Last edited by a moderator:
Paul Nicholls said:
rokdcasbah said:
when you say you can barely see it, you mean that they're all close to black, or to white? maybe the code for picking the color of the lines isn't behaving like you want it to...maybe try just drawing a single color or something. maybe you've already done this though.
The output is really dark...if I peer closely at the screen it seems to have drawn the lines with the random colors but it is hard to tell as the lines are very faint.

I am going to have to try drawing filled rectangles or similar so I can perhaps see better what is going on.

cheers,
Paul.


I have figured it out! It was my 24 bit to 16 bit color conversion routine...it is wrong.

I replaced the color being calculated from the 8 bit r,g,b components with $FFFF for a completely white pixel and the output shows up nicely.

My color conversion routine is currently this:

CODE
Const
cRloss = 5;
cGloss = 6;
cBloss = 5;
cRshift = 11;
cGshift = 5;
cBshift = 0;
{..............................................................................}

{..............................................................................}
Function RGBTo16Bit(r,g,b: Uint8): Uint16;
Begin
Result := ((r Shr cRloss) Shl cRshift) +
((g Shr cGloss) Shl cGshift) +
((b Shr cBloss) Shl cBshift);
End;


I am trying to scale down the 8bit color components to 5 and 6 bits for each color before shifting them to the correct position in the final 16bit color.

Would the new code below be the fastest way to do this?

I am multiplying the r,g,b components by 32,64, and 32 respectively before dividing by 256 and then shifting each result into the correct location

CODE
Const
cRscale = 5;
cGscale = 6;
cBscale = 5;
cRshift = 11;
cGshift = 5;
cBshift = 0;
{..............................................................................}

{..............................................................................}
Function RGBTo16Bit(r,g,b: Uint8): Uint16;
Begin
Result := (((r Shl cRscale) Shr 8) Shl cRshift) +
(((g Shl cGscale) Shr 8) Shl cGshift) +
(((b Shl cBscale) Shr 8) Shl cBshift);
End;


Cheers,
Paul.
 
Last edited by a moderator:
Back
Top