Original Post
Hi
I am working on a software renderer (wireframe only).
After making all that maths library for it am stuk at this GDI function - CreateCompatibleBitmap()
I am trying to draw things on a bitmap and then stretch it to client area of window using BitBlit() function.
Problem is in MakeFrameBuffer() Call to CreateCompatibleBitmap() always failed and as a result it returns false. Even if i let the application running nothing is displayed except a white window.
I have checked my maths library by rendering things in directx using matrices generated by my library.
I have searched alot on net but can't make it work.
Here's some of the code involved -
chWindow - It creates and manages the application window and passes window handle to chSoftwareRenderer
chSoftwareRenderer - It Creates and manages bitmap and presents it application window.
I am working on a software renderer (wireframe only).
After making all that maths library for it am stuk at this GDI function - CreateCompatibleBitmap()
I am trying to draw things on a bitmap and then stretch it to client area of window using BitBlit() function.
Problem is in MakeFrameBuffer() Call to CreateCompatibleBitmap() always failed and as a result it returns false. Even if i let the application running nothing is displayed except a white window.
I have checked my maths library by rendering things in directx using matrices generated by my library.
I have searched alot on net but can't make it work.
Here's some of the code involved -
chWindow - It creates and manages the application window and passes window handle to chSoftwareRenderer
chSoftwareRenderer - It Creates and manages bitmap and presents it application window.
class chSoftwareRenderer{public: chSoftwareRenderer(HWND windowHandle,int width,int height); ~chSoftwareRenderer(void); void GetViewMatrix(const chMatrix* viewMat); void GetProjectionMatrix(const chMatrix* projMat); bool MakeFrameBuffer(); //void EndDrawing(); void ClearFrameBuffer(); void Present(); void DrawPrimitive(chVector3* vertices,int size,const chMatrix* worldMatrix);//private: int wd,ht,vx,vy; chMatrix projMatrix,viewMatrix; HWND wndHandle; HDC hdcFrameBuffer; HBITMAP hbtFrameBuffer,hOldBitmap; void DrawLine(const chVector3* v1,const chVector3 *v2);};chSoftwareRenderer::chSoftwareRenderer(HWND windowHandle){ assert(windowHandle!=0); this->wd = width; ht = height; this->wndHandle = windowHandle; projMatrix.Identity(); viewMatrix.Identity(); RECT rc; GetClientRect(wndHandle,&rc); vx = rc.left; vy = rc.top; wd = rc.right - rc.left; ht = rc.bottom - rc.top;}void chSoftwareRenderer::Present(){ HDC hdc = GetDC(wndHandle); BitBlt(hdc,vx,vy,wd,ht,hdcFrameBuffer,vx,vy,SRCCOPY); ReleaseDC(wndHandle,hdc);}bool chSoftwareRenderer::MakeFrameBuffer(){ HDC hdc = NULL; hdc = GetDC(wndHandle); if(!hdcFrameBuffer) hdcFrameBuffer = CreateCompatibleDC(hdc); if(hbtFrameBuffer) { SelectObject(hdcFrameBuffer,hOldBitmap); DeleteObject(hbtFrameBuffer); hbtFrameBuffer = NULL; hOldBitmap = NULL; } hbtFrameBuffer = CreateCompatibleBitmap(hdcFrameBuffer,wd,ht); if(!hbtFrameBuffer) return false; hOldBitmap = (HBITMAP)SelectObject(hdcFrameBuffer,hbtFrameBuffer); ReleaseDC(wndHandle,hdc); SetBkMode(hdcFrameBuffer,TRANSPARENT);}