Jump to content
  • Advertisement

Archived

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

Darkeye

DirectX Help (to ry)

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

here is my code ry: if anyone else is reading this, it is supposed to blt the colour blue to a small square in the top left of the screen, but instead it makes the whole screen blue directxpong.cpp: /////////////////////////////////// //Main source file for DirectXPong/ //Robert Merrison 14/7/2000//////// //////////////////////////// #include "DirectXPong.h" //Include program header //Global Variables char szClassName[] = "DirectXPong"; char szWindowName[] = "DirectXPong"; int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MSG msg; HWND hWnd; WNDCLASSEX wcl; bool bRunning; ZeroMemory (&wcl, sizeof (WNDCLASSEX)); wcl.cbSize = sizeof (WNDCLASSEX); wcl.hInstance = hInstance; wcl.lpszClassName = szClassName; wcl.lpfnWndProc = WndProc; wcl.style = 0; wcl.lpszMenuName = NULL; wcl.cbClsExtra = NULL; wcl.cbWndExtra = NULL; wcl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wcl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wcl.hCursor = LoadCursor (NULL, IDC_ARROW); wcl.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); if (!RegisterClassEx(&wcl)) { ErrorHandling.ProcessError (ERROR_REGISTER_CLASS); return (-1); } hWnd = CreateWindow (szClassName, szWindowName, WS_POPUP, 0, 0, 640, 480, HWND_DESKTOP, NULL, hInstance, NULL); ShowWindow (hWnd, nShowCmd); InitDDraw (hWnd); hRet = SurFront->Flip(NULL, DDFLIP_WAIT); //Main game loop while (bRunning) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) //Check for messages { if(msg.message == WM_QUIT) { bRunning = false; } TranslateMessage (&msg); DispatchMessage (&msg); } else { } } return 0; } /////////////////////////// //Message handling function /////////////////////////// LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: CleanUpDDraw(); PostQuitMessage(0); return 0; default: return DefWindowProc (hWnd, msg, wParam, lParam); break; } return 0; } ///////////////////// //DDraw Init Function ///////////////////// bool InitDDraw (HWND hWnd) { hRet = DirectDrawCreateEx(NULL, (VOID**)&DDrawObj, IID_IDirectDraw7, NULL); if (hRet != DD_OK) { ErrorHandling.ProcessError (ERROR_INIT_DDRAW); return (false); } hRet = DDrawObj->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if (hRet != DD_OK) { ErrorHandling.ProcessError (ERROR_SET_COOP_LEVEL); return (false); } hRet = DDrawObj->SetDisplayMode(640, 480, 16, 0, 0); if (hRet != DD_OK) { ErrorHandling.ProcessError (ERROR_SET_SCREEN_MODE); return (false); } CreateSurface(hWnd); return (true); } //////////////////////// //DDraw Cleanup Function //////////////////////// void CleanUpDDraw (void) { if (DDrawObj != NULL) { if (SurFront != NULL) { SurFront->Release(); SurFront = NULL; } DDrawObj->Release(); DDrawObj = NULL; } return; } ///////////////////////// //Create surfaces funtion ///////////////////////// bool CreateSurface(HWND hWnd) { DDSURFACEDESC2 ddsd; //Struct for describing surface DDSCAPS2 ddscaps; //Surface flags (?) DDBLTFX ddbltfx; //Struct for blit effects HDC hdc; RECT rect; //Rectangle struct of where to blt ZeroMemory(&ddsd, sizeof(ddsd)); //Empty description struct ddsd.dwSize = sizeof(ddsd); //Set size ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; //Set flags ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; hRet = DDrawObj->CreateSurface(&ddsd, &SurFront, NULL); //Create surface if (hRet != DD_OK) { ErrorHandling.ProcessError (ERROR_CREATING_PRIMARY_SURFACE); return (false); } //Create back buffer ZeroMemory(&ddscaps, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; hRet = SurFront->GetAttachedSurface(&ddscaps, &SurBack); if (hRet != DD_OK) { ErrorHandling.ProcessError (ERROR_CREATING_BACK_BUFFER); return(false); } //Fill back buffer black rect.bottom = 10; rect.top = 1; rect.left = 1; rect.right = 10; ZeroMemory(&ddbltfx, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); ddbltfx.dwFillColor = RGB(255,0,0); SurBack->Blt(&rect, NULL, &rect, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); return (true); }

Share this post


Link to post
Share on other sites
Advertisement
I might be wrong here but I don''t think you can do a colorfill on only a part of the surface. A colorfill fills the entire surface.

What you can do is to make a surface the size you wan''t fill it and then blit that one to the backbuffer.

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!