/** * Main entry point of application. * * @param argc * @param argv */ int main(int argc, char** argv) { std::cout << "Renderfarm 0.1a - by Leon Rodenburg" << std::endl; // Initialize window #ifdef DEBUG std::cout << "DEBUG BUILD - BE PREPARED TO SEE OUTPUT!" << std::endl; RFCore::Logger::GetLogger()->Log("Fetching application handle..."); #else std::cout << "RELEASE BUILD - CONSOLE OUTPUT SUPPRESSED" << std::endl; #endif HINSTANCE hInstance = GetModuleHandle(NULL); WNDCLASSEX windowClass = CreateWindowClass(hInstance); #ifdef DEBUG RFCore::Logger::GetLogger()->Log("Created window class..."); RFCore::Logger::GetLogger()->Log("Opening window..."); #endif khWnd = ::OpenWindow(hInstance, windowClass, kWidth, kHeight); // Initialize world kpWorld = new RFGeometry::World(); kpGeometry = new std::vector<RFGeometry::Geometry*>(); // Initialize kernel kpKernel = new RFCore::Kernel(kpWorld, kNearView, kFarView, kFieldOfView, kWidth, kHeight); // Initialize geometry ::Initialize(); // Add geometry to the world for(unsigned int i = 0; i < kpGeometry->size(); ++i) { kpWorld->AddGeometry(kpGeometry->at(i)); } // Start rendering! return ::Run(); }
void CWin32Workspace::CreateRenderWindow(WindowInitialTarget & init) { if(mContext) throw NOVA_EXP("CWin32Workspace::CreateRenderWindow - \ Render context already created!", BAD_OPERATION); LOG_MESSAGE("Trying make up render window..."); mMetrics.d_buff = init.d_buff; mMetrics.fullscreen = init.fullscreen; mMetrics.freq = init.freq; mMetrics.vsync = init.vsync; mMetrics.FSAA = init.FSAA; mMetrics.DepthBuffered = init.DepthBuffered; if(!mWinClassRegistred) { LOG_MESSAGE("Trying create basic window classes..."); CreateWindowClass(); } PIXELFORMATDESCRIPTOR pfd; memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SWAP_EXCHANGE; if(init.d_buff) pfd.dwFlags |= PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; if(init.color_bits > 16) { pfd.cColorBits = 24; mMetrics.color_bits = 24; } else { pfd.cColorBits = init.color_bits; mMetrics.color_bits = init.color_bits; } pfd.cAlphaBits = (init.color_bits > 16)? 8 : 0; pfd.cDepthBits = 24; pfd.cStencilBits = 8; mColourDepth = mMetrics.color_bits + pfd.cAlphaBits; mColourBits = mMetrics.color_bits; mIsDepthBuffered = init.DepthBuffered; if(mBestPixelFormat == 0) { LOG_MESSAGE("Trying create best pixel format..."); CreateBestPixelFormat(pfd); } char szWindowClass[MAX_LOADSTRING]; DWORD dwStyleEx = 0; DWORD dwStyle = WS_VISIBLE; LoadString(mModuleHandle, IDS_WINCLASS, szWindowClass, MAX_LOADSTRING); if(mMetrics.fullscreen) { //dwStyleEx |= WS_EX_TOPMOST; dwStyle |= WS_POPUP; } else { dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; } nova::uint width, height; if(init.width == 0 || init.height == 0) { width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); } else { width = init.width; height = init.height; } mHwnd = CreateWindowEx(dwStyleEx, szWindowClass, this->mName.c_str(), dwStyle, init.xpos, init.ypos, width, height, NULL, NULL, mModuleHandle, this); if(!mHwnd) throw NOVA_EXP("CWin32Workspace::CreateRenderWindow - \ Can not create render window.", BAD_OPERATION); //SetWindowLongPtr(mHwnd, GWLP_USERDATA, (LONG_PTR)this); HDC hdc = GetDC(mHwnd); if(!hdc) throw NOVA_EXP("CWin32Workspace::CreateRenderWindow - \ Can not create compatible device context!", BAD_OPERATION); mContext = new CWGLContext(hdc); //////////////////////// //mBestPixelFormat = ChoosePixelFormat(hdc, &pfd); //////////////////////// dynamic_cast<CWGLContext *>(mContext)->CreateRenderContext(&pfd, mBestPixelFormat); { nstring str("Render context on pixel format created: 0x"); str.append(CStringUtils::IntTo16xString((int) dynamic_cast<CWGLContext *>(mContext)->GetRenderContext())); LOG_MESSAGE(str); } if(mBestFormatFinded) glEnable( GL_MULTISAMPLE_ARB ); /* if(mWindowsCount > 1) { HGLRC oldrc = wglGetCurrentContext(); if(!wglShareLists(oldrc, dynamic_cast<CWGLContext *>(mContext)->GetRenderContext())) throw NOVA_EXP("CWin32Workspace::CreateRenderWindow - \ Can not share old and new contexts.", BAD_OPERATION); } */ mContext->SetCurrent(); nstring swapext("WGL_EXT_swap_control"); if(mSupport->CheckExtention(swapext)) { if(mMetrics.vsync) wglSwapIntervalEXT(1); else wglSwapIntervalEXT(0); } RECT rc; // top and left represent outer window position GetWindowRect(mHwnd, &rc); mMetrics.xpos = rc.top; mMetrics.ypos = rc.left; mXPosition = rc.top; mYPosition = rc.left; GetClientRect(mHwnd, &rc); mWidth = rc.right; mHeight = rc.bottom; mMetrics.width = mWidth; mMetrics.height = mHeight; if(mMetrics.fullscreen) SetScreenSettings(); ShowWindow(mHwnd, SW_SHOWNORMAL); UpdateWindow(mHwnd); SetCursorPos(mMetrics.width >> 1, mMetrics.height >> 1); LOG_MESSAGE("Render window successfully created!"); mReady = true; }