All pixels not drawing?

Started by
6 comments, last by L. Spiro 9 years, 1 month ago

Hello!
I'm making a game(obviously, GAMEdev.net hehe), but I'm having some problems.
When drawing, everything is not shown.

Here is an example:

e75763427250caab43a3f3e77d80258b.png

Code:


void MenuButton(int x1, int y1, int x2, int y2, const char *fmt)
{
	DrawFilledBox(x1, y1, 200, 50, LightGray1);
	DrawLinedBox(x1, y1, 200, 50, 2, Black);

	DrawShadowString(x1 + x2, y1 + y2, White, pFont_20, fmt);
}

void Menu()
{
	MenuButton(300, 175, 75, 15, "Play");

	MenuButton(300, 250, 50, 15, "Options");
}
void Render()
{
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1, 0);
	d3ddev->BeginScene();

	Menu();

	d3ddev->EndScene();
	d3ddev->Present(NULL, NULL, NULL, NULL);
} 

Why is this happening?

Advertisement

First, welcome to gamedev!

Second, please read the Beginner's FAQ, as it will help you ask questions in a better way.

From a logic standpoint: programs are comprised of code, and the data that the code uses. If your buttons are rendered using the same code, then the data must be different. Assuming the "play" button renders as you desire, have you looked at the actual values being used to render the "options" button to determine if they're correct?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

First, welcome to gamedev!

Second, please read the Beginner's FAQ, as it will help you ask questions in a better way.

From a logic standpoint: programs are comprised of code, and the data that the code uses. If your buttons are rendered using the same code, then the data must be different. Assuming the "play" button renders as you desire, have you looked at the actual values being used to render the "options" button to determine if they're correct?

Edited in the code used.
Resolution of the window is 800x600, if that matters.


have you looked at the actual values being used to render the "options" button to determine if they're correct?

To make it a little clearer, if the data used by the code does not provide the results you want, either the data is incorrect, the code is incorrect, or both. What have done to determine where the problem occurs?

Just a guess, without knowing how DrawLinedBox is coded (your own function?), it appears that's the place where the problem occurs. Do you have the same problem if you draw only the lines? Do you have the same problem if you don't draw the text? Or the filled rectangle?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Resolution of the window is 800x600, if that matters.

Lucky guess, a common beginner pitfall: Mismatch between backbuffer and windows client size. Also check viewport and projection.

Could you post the code behind the three Draw functions you invoke in MenuButton? Perhaps that gives more insight in possible error causes.

@unbird: If he uses D2D draw functions in there projection shouldn't matter, should it?

He's using D3D9 so unlikely D2D at work here :wink:

Yes you don't have an explicit projection in D2D (one can use a global transformation though), but if your backbuffer (D3D11: swapchain) doesn't match then you will have such distortions. If there's such a mismatch, chances are the projection and viewport are also amiss, that's why I suggested a look.

If he's using ID3DXSprite and -Font he's probably fine, though.

But yeah, a look at actual setup and draw code should reveal more.

This type of thing is often caused by having an orthogonal projection matrix 1 pixel too small in each direction (or other rounding errors).
Expand the projection matrix by 1 in each direction.

You may also add a half-pixel shift to account for the fact that Direct3D 9 addresses pixel corners rather than pixel centers.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement