void MyWindow::draw() { if( !valid() ) { GLenum err = glewInit(); if (err != GLEW_OK) exit(1); if (!GLEW_VERSION_3_3) exit(1); pe.Init(); ve.Init(); objects.push_back(Object(&pe,numv)); //Requires glewInit to be run. } Vstep(); glDrawBuffer(GL_BACK); }
//Initialise the render world void init() { glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE ); //glEnable( GL_CULL_FACE ); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor( 0, 0.0, 0.0, 0.0 ); // Light 0 parameters GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_ambient[] = { 0.3, 0.3, 0.3, 1.0 }; GLfloat light_position[] = { 1.0, 0.0, 1.0, 0.0 }; // Setup light 0 glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, mat_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_specular); // Turn light on! :) glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); physEngine.Init(); }
HRESULT Application::Init(HINSTANCE hInstance, bool windowed) { g_debug << "Application Started \n"; //Create Window Class WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WndProc; wc.hInstance = hInstance; wc.lpszClassName = "D3DWND"; RECT rc = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false); //Register Class and Create new Window RegisterClass(&wc); m_mainWindow = ::CreateWindow("D3DWND", "Character Animation with Direct3D: Example 6.3", WS_OVERLAPPEDWINDOW, 0, 0, rc.right - rc.left, rc.bottom - rc.top, 0, 0, hInstance, 0); SetCursor(NULL); ::ShowWindow(m_mainWindow, SW_SHOW); ::UpdateWindow(m_mainWindow); //Create IDirect3D9 Interface IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if (d3d9 == NULL) { g_debug << "Direct3DCreate9() - FAILED \n"; return E_FAIL; } //Check that the Device supports what we need from it D3DCAPS9 caps; d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); //Check vertex & pixelshader versions if (caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) { g_debug << "Warning - Your graphic card does not support vertex and pixelshaders version 2.0 \n"; } //Set D3DPRESENT_PARAMETERS m_present.BackBufferWidth = WINDOW_WIDTH; m_present.BackBufferHeight = WINDOW_HEIGHT; m_present.BackBufferFormat = D3DFMT_A8R8G8B8; m_present.BackBufferCount = 2; m_present.MultiSampleType = D3DMULTISAMPLE_NONE; m_present.MultiSampleQuality = 0; m_present.SwapEffect = D3DSWAPEFFECT_DISCARD; m_present.hDeviceWindow = m_mainWindow; m_present.Windowed = windowed; m_present.EnableAutoDepthStencil = true; m_present.AutoDepthStencilFormat = D3DFMT_D24S8; m_present.Flags = 0; m_present.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; m_present.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //Hardware Vertex Processing int vp = 0; if ( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //Create the IDirect3DDevice9 if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow, vp, &m_present, &g_pDevice))) { g_debug << "Failed to create IDirect3DDevice9 \n"; return E_FAIL; } //Release IDirect3D9 interface d3d9->Release(); //Load Application Specific resources here... D3DXCreateFont(g_pDevice, 20, 0, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &g_pFont); //Create Sprite D3DXCreateSprite(g_pDevice, &g_pSprite); //Load Effect ID3DXBuffer *pErrorMsgs = NULL; HRESULT hRes = D3DXCreateEffectFromFile(g_pDevice, "resources/fx/lighting.fx", NULL, NULL, D3DXSHADER_DEBUG, NULL, &g_pEffect, &pErrorMsgs); if (FAILED(hRes) && (pErrorMsgs != NULL)) { //Failed to create Effect g_debug << (char*)pErrorMsgs->GetBufferPointer() << "\n"; return E_FAIL; } LoadParticleResources(); physicsEngine.Init(); m_deviceLost = false; return S_OK; }