Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

qadir

Stars

This topic is 5586 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''m an absolute newbie, so I decided to start with something as simple as a starfield written in C. It is just a basic plotting of pixels randomly on the screen and then changing their positions. My code is somewhat as follows /* Get the current device context */ hdc = GetDC(hwnd); /* Set up a buffer device context */ bufdc = CreateCompatibleDC(hdc); I''m using SetPixel to plot the changed pixels onto the new DC i.e bufdc and then trying to load it into memory using BitBlt(hdc,0,0,rect.right,rect.bottom,bufdc,0,0,SRCCOPY) However, I just can''t get it to work. Could someone please help as to where I''m going wrong. Also ant advice as to what a rank newcomer such as me might read, would be greatly appreciated Thx Qadir All Sprites are created equal

Share this post


Link to post
Share on other sites
Advertisement
Is this DirectX you are using? If so, you do not need to blit anything to the screen. when you plot a pixel, that''s exactly what it does..

If you don''t have a backbuffer then it should just show up on the screen with no additional work required.

Share this post


Link to post
Share on other sites
Well, I'm not using directX, I've directly used GetDC to get the handle to device context.

If I use

SetPixel(hdc,400,400,RGB(red,green,blue));

I can see the pixel on screen. So I thought I would write the pixels to a buffer DC which I got using GetCompatibleDC and once the pixels have been plotted I would use BitBlt to transfer the pixels from bufdc to hdc.

When I say it doesn't work, I mean that the pixels written on dc remain, while the pixels on bufdc fail to appear. Its as if BitBlt has no effect. However if I pass the parameter as WHITENESS instead of SRCCOPY, the screen turns white so I know BitBlt is working.

I think there might be some other problem, since even the pixels on hdc disappear if I minimise the window and then remaximise it

[edited by - qadir on July 5, 2003 5:47:00 AM]

Share this post


Link to post
Share on other sites
Maybe you have to select a bitmap into bufdc?

HBITMAP bufbmp = CreateCompatibleBitmap(windowWidth,windowHeight);
SelectObject(bufdc,bufbmp);

Share this post


Link to post
Share on other sites
quote:
Maybe you have to select a bitmap into bufdc?


Okay, but then how do I plot pixels onto a bitmap

All Sprites are created equal

Share this post


Link to post
Share on other sites
If I understood right, your method involves loading a bitmap onto the buffer dc and then blitting it to hdc. I''m sure that would work since I have already tried blitting bitmaps using this technique and it has worked.

However what I need is someway to plot the stars at changing locations everytime so as to simulate the effect of a starfield. If I blit with the bitmap, the bitmap must contain the pixels at their new position so as to succeed. So I need to plot the pixels onto the bitmap before using your method and this is the part I do not understand.

All Sprites are created equal

Share this post


Link to post
Share on other sites
My guess is that the window is just not updating. Why are you not drawing your stars in the WM_PAINT message handler? Are you ever calling InvalidateRect() to make sure that the window is redrawn?



Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites
quote:
Are you ever calling InvalidateRect() to make sure that the window is redrawn


I didn''t know about that, I''ll try it and let u know. I was able to get the effect using DirectX, however since I''m using only the primary surface, there is no hardware acceleration and it seems kinda slow.

I have put up the directX source here but don''t expect anything too advanced, since it is my first directX program.
As soon as I fully understand the part about how to use page flipping with the back buffer, I''ll update the code so that the effect is not so jerky.

Here it is

www.geocities.com/abdul_stud/dx.txt

All Sprites are created equal

Share this post


Link to post
Share on other sites

  • 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!