Jump to content
  • Advertisement
Sign in to follow this  
Pradip Bhattacharya

Drawing a 2D array on to the screen

This topic is 4420 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

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]

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ????

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!