Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 3 của 3
  1. #1

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    lổi khi làm việc với directX ?

    mình đang bắt đầu làm quen với direct , thử gỏ lại một bài như trong ebook nhưng nó bào lổi mà mình ko hiểu. nhờ mọi người coi giúp
    Mã:
    #include<windows.h>
    #include<d3d9.h>
    HINSTANCE hInst; //khai bao the hien cua ung dung
    //HWND wndHandle; //khai bao con tro quan li cua so ung dung
    wchar_t vidu[]=L"vidu1";
    
    LPDIRECT3D9 pd3d9=NULL; //khai bao doi tuong direct3D
    LPDIRECT3DDEVICE9 dv3d9=NULL; //khai bao thiet bi direct3D
    //khai bao ham
    bool initWindow(HINSTANCE hinstance);
    bool initDirect3D(HWND);
    void render(void);
    LRESULT CALLBACK MsgProc(HWND,UINT,WPARAM,LPARAM);
    int WINAPI  WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
    {
    //khoi tao ung dung
    	if(!initWindow(hInstance))
    		return false;
    
      //vong lap quan li thong diep
    	MSG msg;
         ZeroMemory(&msg,sizeof(msg));
    	while(msg.message!=WM_QUIT)  //khi chua phai thong dipe ket thuc ung dung
    	{
          //kiem tra cac thong diep dc gui toi trong hang doi cua ung dung
    		
      if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
      {
         TranslateMessage(&msg);
    	 DispatchMessage(&msg);
    
    
      }
      else
      {
    	  render();
      }
    
    	}
        
    	return (int)msg.wParam;
    }
    
    bool initWindow(HINSTANCE hinstance)
    {
    	WNDCLASSEX wd;
    	wd.cbSize=sizeof(WNDCLASSEX);
    	wd.hbr   wd.cbClsExtra=0;
    	wd.cbWndExtra=0;
    	wd.hCursor=LoadCursor(NULL,IDC_ARROW);
        wd.hIcon=0;
    	wd.style=CS_HREDRAW|CS_VREDRAW;
        wd.lpfnWndProc=(WNDPROC)MsgProc;
    	wd.lpszMenuName=NULL;
    	wd.lpszClassName=vidu;
    	
    
    	wd.hIconSm=0;//con tro toi du lieu bieu tuong cua doi tuong
    	wd.hInstance=hinstance; //con tro tro toi instance cua ung dung
    	RegisterClassEx(&wd);
    	HWND wndHandle;
    	wndHandle=CreateWindow(
    		                vidu,
    					    L"window",
    						WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,
    						CW_USEDEFAULT,
    						600,
    						600,
    						NULL,
    						NULL,
    						hinstance,
    						NULL); 
    
    	//kiem tra xem qua trinh tao cua so co hoan thanh ko
    	if(!wndHandle)
    		return false;
    	//the hien cua so len man hinh
    	ShowWindow(wndHandle,SW_SHOW);
        UpdateWindow(wndHandle);
    
    		if(!initDirect3D(wndHandle))
    		return false;
    	return true;
       
    }
    LRESULT CALLBACK MsgProc(HWND wndHandle,UINT message,WPARAM wparam,LPARAM lparam)
    {
      //kiem tra xem co thong diep nao gui toi hang doi cua ung dung ko
    	switch(message)
    		case WM_DESTROY:
    	{
    			PostQuitMessage(0);
    			break;
    	}
    	return DefWindowProc(wndHandle,message,wparam,lparam);
    
    
    
    }
    bool initDirect3D(HWND wndHandle)
    {
      //tao doi tuong directX
      pd3d9=Direct3DCreate9(D3D_SDK_VERSION);
    
      D3DPRESENT_PARAMETERS d3dpp;
      ZeroMemory(&pd3d9,sizeof(pd3d9));
      d3dpp.Windowed=true;
      //d3dpp.BackBufferCount=1;
      d3dpp.BackBufferFormat=D3DFMT_UNKNOWN;
      //d3dpp.BackBufferHeight=600;
      //d3dpp.BackBufferWidth=600;
      d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
     // d3dpp.hDeviceWindow=wndHandle;
      //tao doi tuog direct
      pd3d9->CreateDevice(
    	                  D3DADAPTER_DEFAULT,
    	                  D3DDEVTYPE_HAL,
    					  wndHandle,
    					  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    					  &d3dpp,
    					  &dv3d9
    					  );
     if(pd3d9==NULL)
    	 return false;
     
    
      return true;
    }
    void render()
    {
      if(pd3d9==NULL)
    	  return;
      //xoa bo dem cua thiet bi ve mau xanh 
      dv3d9->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255),1.0f,0);
      
      dv3d9->Present(NULL,NULL,NULL,NULL); //cho hien thi len man hinh
    
    }
    đây là thông báo lổi:

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Copy code ở đâu hay gõ thí xác vào phải không đại ca:

    Mã:
    //tao doi tuong directXpd3d9=Direct3DCreate9(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&pd3d9,sizeof(pd3d9));
    Khởi tạo pd3d9 xong ZeroMemory nó đi, đáng lý phải ZeroMemory d3dpp chứ ????

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •