About Store Forum Documentation Contact



Post Reply 
Rendering pixel buffer
Author Message
SONB Offline
Member

Post: #1
Rendering pixel buffer
Hi, Esenthel!

I'm trying to implement the Hikari library, as I said in the Gamedev Tools forum.
Well, Hikari creates every frame a pixel buffer (unsigned char* buffer), which should be rendered in the viewport. Now how can I do it in Esenthel engine?
I thought about creating a 2D image, like in the Dynamic Image tutorial, and copying the buffer's data to the image. But how can I iterate through each pixel of this buffer and copy them to my Image?

Thanx a lot in advance!


SONB
07-03-2009 02:04 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Rendering pixel buffer
Hi,

Yes, the dynamic image tutorial is exactly what you need.
But you have there described setting pixel colors so what's exactly the problem?

first you need to lock an image, fill the pixels, and then unlock it.

if the type's of the image buffers match (for example Hikari uses buffer A8R8G8B8, and you create a texture of A8R8G8B8 then you can optimize the copying to be faster, by using 'Copy' raw memory function for each row separately)

Code:
image.lock(..)
REPD(y,image.y())Copy(image.data + image.pitch*y, source_buffer.data + y*source_buffer.pitch, Min(image.pitch, source_buffer.pitch));
image.unlock(..);

something like that
07-03-2009 10:17 AM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #3
Re: Rendering pixel buffer
Hmm, I tried your Copy(...) method and I'm getting a grey rectangle. Maybe the types don't match?

There is a function in the Hikari library, which confuses me:
Code:
void RenderBuffer::blitBGR(unsigned char* destBuffer, int destRowSpan, int destDepth)
{
    if(destDepth == 3)
    {
        for(int row = 0; row < height; row++)
            for(int col = 0; col < width; col++)
                memcpy(destBuffer + row * destRowSpan + col * 3, getBuffer() + row * rowSpan + col * 4, 3);
    }
    else if(destDepth == 4)
    {
        for(int row = 0; row < height; row++)
            memcpy(destBuffer + row * destRowSpan, getBuffer() + row * rowSpan, rowSpan);
    }
}

destBuffer is my Image, getBuffer() returns the render buffer of Hikari. What confuses me is the name of the function: blitBGR(...). BlueGreenRed... not RGB. Could this be a problem? Do I have to copy the render buffer into my Image in the right order (BGR->RGB)? If so, how?
Another question: How can I copy the buffer like in the Dynamic Image tutorial? I mean, I know, how to iterate through each pixel of my Image, but how can I iterate through the pixels of the render buffer of Hikari (it's an unsigned char*) and copy them into my Image?

Sorry but I'm a complete noob in render buffers :?

And again, thanx a lot for your help!
07-04-2009 01:25 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
Re: Rendering pixel buffer
wheter it's BGR or RGB you still should get some colors.

tell me how you're creating the Image ? (what parameters are you giving) ?
and how do you call the blitBGR method? (what params)
07-04-2009 11:30 AM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #5
Re: Rendering pixel buffer
Esenthel Wrote:wheter it's BGR or RGB you still should get some colors.
That's what I thought too.

Well there are two steps how Hikari creates my image.
The first:
Code:
Image texture;
texture.create2D(texWidth, texHeight, IMAGE_A8R8G8B8, 1);

texture.lock();
texDepth = texture.bpp();
texPitch = texture.pitch();
unsigned char* pDest = static_cast<unsigned char*>(texture.data());
memset(pDest, 128, texHeight*texPitch);
texture.unlock();
Here Hikari initializes the texture and fills it with grey color.

Then the second step (called every frame in Hikari::update()):
Code:
update() {
    ...

    texture.lock();
    unsigned char* destBuffer = static_cast<unsigned char*>(texture.data());
    renderBuffer->blitBGR(destBuffer, (int)texPitch, (int)texDepth);
    texture.unlock();
}
That's it. Update() just makes no changes to my texture, it stays grey.
07-04-2009 03:02 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
Re: Rendering pixel buffer
what are these texWidth and texHeight?

maybe the hikari getBuffer just returns grey values?

could you check it what it actually returns? see its memory or save it to a file

could you debug the Update
and see if these codes actually get executed:
void RenderBuffer::blitBGR(unsigned char* destBuffer, int destRowSpan, int destDepth)
{
07-04-2009 04:27 PM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #7
Re: Rendering pixel buffer
texWidth and texHeight define the texture dimensions.

EDIT: I debugged the update() function and found out that it's not even executed... :?
I'm investigating the Hikari class right now.
07-04-2009 04:38 PM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #8
Re: Rendering pixel buffer
Oh god, that's so embarassing... I put the Hikari::update() in the main update() function AFTER return true; and not BEFORE... So it was never called :oops:

Ok, the best part is, now I can see the Flash image in my Esenthel app grin Even it's colors are correct. Thanx, Esenthel!
But, here comes the next problem: First, my image is drawn stretched vertically; second, it's 3-4 times bigger than it should be.
I saved the image as a JPG file and it has correct dimensions. Now, as you said, I want to save the renderBuffer of Hikari to compare the both images. How can I do that?
07-04-2009 05:12 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
Re: Rendering pixel buffer
maybe you need just to draw it differently?

Image::draw

how are you drawing it currently?
07-04-2009 05:51 PM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #10
Re: Rendering pixel buffer
Like this:

texture.draw(-0.5, 0.5, 1, 1);

It's dimensions should be: 130x91px, but it's much bigger.

I'm looking at the implementation of Hikari in Ogre and there's a code, which looks if texWidth and texHeight are power of 2 -> if not, it looks if the render system supports it. Does Esenthel have such functions, like isPO2() in Ogre? And how can I check the capabilities of the render system?
07-04-2009 06:29 PM
Find all posts by this user Quote this message in a reply
Sarora Offline
Member

Post: #11
Re: Rendering pixel buffer
I myself have some serious issues with size x,y, also because the coordinate system on a 1680x1050 setting is 1600 (+/- x) and 1000 (+/- y), seems wierd

appears though, if you take the image width / 1000 and image height / 1000 * aspect ratio, you get the size (apparently).

the coordinate system in this engine is freaking me out pfft (eg 16:10 is width +1600 to -1600, and height +1000 to -1000) and i would guess 4:3 is +/-1333 w and +/- 1000 h..

i find hard to get correct positions for scaling image up to fix in width only and autoscale to match the new width with height (aspect) ect ect.

Edit, EG

topBar.draw(Rect_LU(-D.w(), D.h(), D.w() * 2, 0.1408));

Makes a 1920x88 image fit in full width at topline and correct scaled (manually) in height ( 88 / 1000 * 1.6) = 0.1408 where 1.6 is aspect ratio for 16:10

I dont know if it can be done better or something tbh..

Another edit :

Changed it to

Flt imageWidthA = MyImage.x() / 1000.0 * D.aspectDisplay(); // gives image with correct size with aspect
Flt imageHeightA = MyImage.y() / 1000.0 * D.aspectDisplay(); // gives image with correct size with aspect

Then, to draw it in center, you could do

MyImage.draw(0 + imageWidthA / 2, 0 + imageHeightA / 2, imageWidthA, imageHeightA);

Sys: Intel Quad @3.4 Ghz, ATI HD 5770 OC Ed (pri), NVIDIA 8800 Ultra (PhysX), 4 Gig Ram, 3.8 TB total HDD.
07-04-2009 08:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #12
Re: Rendering pixel buffer
Code:
draw(-0.5, 0.5, 1, 1);
you can just change the size in this function

Quote:myself have some serious issues with size x,y, also because the coordinate system on a 1680x1050 setting is 1600 (+/- x) and 1000 (+/- y), seems wierd
it is not 1600,1000 but it's -1.6 .. 1.6 and -1..1

it's not per pixel system

Y is always -1..1
X is calculated proportionally
07-04-2009 09:57 PM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #13
Re: Rendering pixel buffer
Hi, Esenthel!

I'm trying to set up the mouse input for Hikari. The Ogre example says that I must inject absolute mouse coordinates in screen-space into Hikari, so that the Flash movie knows how to react, when the cursor is over or out of it. Well there is a function HikariManager::injectMouseMove(short x, short y). I'm trying to inject the coordinates with Ms.win_posi.abs().x and Ms.win_posi.abs().y, but there is a problem: The dimensions of the window are 1024x768, 16:10, and for example the left upper corner of the screen is not (0,0) and the right bottom corner is not (1024,768). I have to move the mouse far out of the screen to reach the limits.
So is there a way to 'squeeze' mouse coordinates to match the resolution?

Thanx in advance!


EDIT: And thanx, Sarora! Your code works like a charm grin
07-05-2009 02:12 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #14
Re: Rendering pixel buffer
hi, i dont exactly understand.

but ill say you shouldnt call here 'abs'
Ms.win_posi.abs().x
use just Ms.win_posi.x
07-05-2009 02:26 PM
Find all posts by this user Quote this message in a reply
SONB Offline
Member

Post: #15
Re: Rendering pixel buffer
Sorry, I'll try to explain it better.

There are differences in absolute mouse coordinates between Esenthel and Ogre. For example, I let Ogre output absolute mouse coordinates on the screen, to visually compare the position of the cursor on the screen with its coordinates. Assuming that the resolution of the window is 1024x768, when I move the cursor to the left top corner, Ogre says: "Mouse coords: 0, 0" and in the right bottom corner it would say: "Mouse coords: 1024x768"... Do you know what I mean? smile
The problem is: I don't see the same results in Esenthel. The coordinates are always wrong, doesn't matter, abs() or not...
07-05-2009 03:42 PM
Find all posts by this user Quote this message in a reply
Post Reply