static void initShader( int *pid, const char *vs, const char *fs ) { pid[0] = oglCreateProgram(); const int vsId = oglCreateShader( GL_VERTEX_SHADER ); const int fsId = oglCreateShader( GL_FRAGMENT_SHADER ); oglShaderSource( vsId, 1, &vs, 0 ); oglShaderSource( fsId, 1, &fs, 0 ); oglCompileShader( vsId ); oglCompileShader( fsId ); oglAttachShader( pid[0], fsId ); oglAttachShader( pid[0], vsId ); oglLinkProgram( pid[0] ); #ifdef DEBUG int result; char info[1536]; oglGetObjectParameteriv( vsId, GL_OBJECT_COMPILE_STATUS_ARB, &result ); oglGetInfoLog( vsId, 1024, NULL, (char *)info ); if( !result ) DebugBreak(); oglGetObjectParameteriv( fsId, GL_OBJECT_COMPILE_STATUS_ARB, &result ); oglGetInfoLog( fsId, 1024, NULL, (char *)info ); if( !result ) DebugBreak(); oglGetObjectParameteriv( pid[0], GL_OBJECT_LINK_STATUS_ARB, &result ); oglGetInfoLog( pid[0], 1024, NULL, (char*)info ); if( !result ) DebugBreak(); #endif }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc; // create window ZeroMemory( &wc, sizeof(WNDCLASS) ); wc.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hPrevInstance; wc.lpszClassName = "iq"; if( !RegisterClass(&wc) ) return( 0 ); const int dws = WS_VISIBLE | WS_CAPTION | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU; AdjustWindowRect( &rec, dws, 0 ); HWND hWnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, wc.lpszClassName, "accio", dws, (GetSystemMetrics(SM_CXSCREEN)-rec.right+rec.left)>>1, (GetSystemMetrics(SM_CYSCREEN)-rec.bottom+rec.top)>>1, rec.right-rec.left, rec.bottom-rec.top, 0, 0, hPrevInstance, 0 ); if( !hWnd ) return( 0 ); HDC hDC=GetDC(hWnd); if( !hDC ) return( 0 ); // init opengl int pf = ChoosePixelFormat(hDC,&pfd); if( !pf ) return( 0 ); if( !SetPixelFormat(hDC,pf,&pfd) ) return( 0 ); HGLRC hRC = wglCreateContext(hDC); if( !hRC ) return( 0 ); if( !wglMakeCurrent(hDC,hRC) ) return( 0 ); // init extensions for( int i=0; i<(sizeof(funcPtrs)/sizeof(void*)); i++ ) { funcPtrs[i] = wglGetProcAddress( funcNames[i] ); if( !funcPtrs[i] ) return 0; } // create shader int p = oglCreateProgram(); // int v = oglCreateShader(GL_VERTEX_SHADER); // oglShaderSource(v, 1, &vertexShader, 0); // oglCompileShader(v); // oglAttachShader(p,v); int f = oglCreateShader(GL_FRAGMENT_SHADER); oglShaderSource(f, 1, &fragmentShader, 0); oglCompileShader(f); oglAttachShader(p,f); oglLinkProgram(p); oglUseProgram(p); ShowCursor(0); // run /* do { glColor3f(t,sinf(.25f*t),0.0f); glRects(-1,-1,1,1); SwapBuffers(hDC); //wglSwapLayerBuffers( hDC, WGL_SWAP_MAIN_PLANE ); }while ( !GetAsyncKeyState(VK_ESCAPE) ); */ int done = 0; while( !done ) { const float t = .0025f*(float)(GetTickCount()&65535); MSG msg; while( PeekMessage(&msg,0,0,0,PM_REMOVE) ) { if( msg.message==WM_QUIT ) done=1; TranslateMessage( &msg ); DispatchMessage( &msg ); } glColor3f(t,sinf(.25f*t),0.0f); glRects(-1,-1,1,1); SwapBuffers( hDC ); } ExitProcess( 0 ); return 0; }