Drawing a 2D array on to the screen

Started by
5 comments, last by Pradip Bhattacharya 17 years, 6 months ago
Hi, I am trying to draw a 2D array on to the screen. I am using SetDIBitsToDevice function...in every update loop i am assigning a value (int the form RGB) to the array and i am calling the function SetDIBitsToDevice.. The window size is 640 x 480. The FPS which I am getting is pretty low...something around 70. #define ARRAY_WIDTH 640 #define ARRAY_HEIGHT 480 #define BYTESPERPEL 3 unsigned char *RGBArray; RGBArray = new unsigned char[WIDTH * HEIGHT * BYTESPERPEL ]; // update the array with new values for every loop ::SetDIBitsToDevice(BLA,BLA,BLA,.....); Please do let me know how to increase the FPS. Regards Pradip [Edited by - Pradip Bhattacharya on October 16, 2006 2:47:28 AM]
Advertisement
70 fps is not low. A television operates at ~30 fps.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
That sounds and awfull lot like a monitors vsync rate.
I think I was not able to correctly present my doubt....actually in the update loop...currently i am not doing much...I mean i am only assigning values to the elements of the array..i am trying to write a function ClearBuffer(BYTE red,BYTE green,BYTE blue)...

int ArrayWidthEx = ARRAY_WIDTH * 3;
int CurrentY;

for(register int y = 0;y < ARRAY_HEIGHT;y++)
{
CurrentY = y * ArrayWidthEx;
for(register int x = 0;x < ArrayWidthEx;x+=3)
{
RGBArray[CurrentY + x] = red;
RGBArray[CurrentY + x + 1] = green;
RGBArray[CurrentY + x + 2] = blue;
}
}


so...this is the only update that i am doing..and this giving out only 70 FPS....so when i will actually try to render triangles on to the buffer then wouldnt the FPS be near to something like 10 - 20....i know i am too new to judge such a value..but then also isnt the current FPS low??? and what can i do to increase the FPS ??

[Edited by - Pradip Bhattacharya on October 16, 2006 2:37:42 AM]
I concur on that 70 FPS seems like a quite reasonable FPS for software rendering, especially if the screen updates at about 75 Hz. The device buffer that you draw to might be locked at times by the graphics system (GDI) so that it can copy the graphics to the screen buffer (v-synched). If it's locked calls to functions that access the device might have to wait. Also, DIBs (device independent) are converted to the color format that the final device currently uses, and the conversion can be slow.

On MSDN there's a heading about Shortcomings of DIBS, at the bottom of the page.

You can use a memory device context which isn't locked and has the same color format as the final device. This way you can draw lots of for example triangles to it, and when all triangles are done, copy the whole memory buffer (backbuffer) to the final device once and avoid color format conversion.

You can read more about it on MSDN: Memory Device Contexts.
Quote:Original post by Pradip Bhattacharya

#define ARRAY_WIDTH 640
#define ARRAY_HEIGHT 480
#define BITSPERPEL 24

unsigned char *RGBArray;

RGBArray = new unsigned char[WIDTH * HEIGHT * BITSPERPEL];




Be aware that if this is your actual array declaration, it is 8 times too big.

it should be WIDTH * HEIGHT * (BITSPERPEL / 8).

Also I agree that it is most likely your monitor refresh rate. Change it in windows display properties to 60, and then see if you only get 60 fps.
Waramp.Before you insult a man, walk a mile in his shoes.That way, when you do insult him, you'll be a mile away, and you'll have his shoes.
thanks WarAmp...i actually made a mistake in writing the post...well i am using mingW compiler..yesterday i saw an option of "optimise for speed"....after using that option the FPS was 90...but I am not yet able to draw the array using BitBlt...I tried to do what Dim_Yimma_H suggested... i created a memoryDC and SelectObject(memoryDC,hBitmap) but event after that i am not able to draw the array using BitBlt...can i get any such code which implements BitBlt to draw 2D array on to device screen ????

This topic is closed to new replies.

Advertisement