int WINAPI WinMain( HINSTANCE instance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; int done=0; WININFO *info = &wininfo; info->hInstance = GetModuleHandle( 0 ); //if( MessageBox( 0, "fullscreen?", info->wndclass, MB_YESNO|MB_ICONQUESTION)==IDYES ) info->full++; if (!window_init(info)) { window_end(info); MessageBox(0, "window_init()!", "error", MB_OK|MB_ICONEXCLAMATION); return 0; } if (initGL(info)) { return 0; } //intro_init(); // Initialize COM HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) exit(-1); // Example editor usage char errorText[MAX_ERROR_LENGTH+1]; char filename[SM_MAX_FILENAME_LENGTH+1]; sprintf_s(filename, SM_MAX_FILENAME_LENGTH, "shaders/%s", usedShader[usedIndex]); if (editor.loadText(filename, errorText)) { MessageBox(info->hWnd, errorText, "Editor init", MB_OK); return -1; } start_time_ = timeGetTime(); long last_time = 0; while( !done ) { long t = timeGetTime() - start_time_; while( PeekMessage(&msg,0,0,0,PM_REMOVE) ) { if( msg.message==WM_QUIT ) done=1; TranslateMessage( &msg ); DispatchMessage( &msg ); } glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); intro_do(t, t - last_time); editor.render(t); last_time = t; SwapBuffers( info->hDC ); } window_end( info ); #ifdef MUSIC // music uninit BASS_Free(); #endif // Un-initialize COM CoUninitialize(); return( 0 ); }
/** * @brief Load and initialize shaders */ virtual void initialize (void) { initGL(); // searches in default shader directory (/shaders) for shader files NormalVector.(vert,frag,geom,comp) loadShader(normalvec_shader, "normalvector"); }
int main( int argc, char **argv ) { /* Flags to pass to SDL_SetVideoMode */ int videoFlags; /* main loop variable */ int done = FALSE; /* used to collect events */ SDL_Event event; /* this holds some info about our display */ const SDL_VideoInfo *videoInfo; /* whether or not the window is active */ int isActive = TRUE; /* initialize SDL */ if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); Quit( 1 ); } /* Fetch the video info */ videoInfo = SDL_GetVideoInfo( ); if ( !videoInfo ) { fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) ); Quit( 1 ); } /* the flags to pass to SDL_SetVideoMode */ videoFlags = SDL_OPENGL; /* Enable OpenGL in SDL */ videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */ videoFlags |= SDL_HWPALETTE; /* Store the palette in hardware */ videoFlags |= SDL_RESIZABLE; /* Enable window resizing */ /* This checks to see if surfaces can be stored in memory */ if ( videoInfo->hw_available ) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; /* This checks if hardware blits can be done */ if ( videoInfo->blit_hw ) videoFlags |= SDL_HWACCEL; /* Sets up OpenGL double buffering */ SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); /* get a SDL surface */ surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags ); /* Verify there is a surface */ if ( !surface ) { fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); Quit( 1 ); } /* Enable key repeat */ if ( ( SDL_EnableKeyRepeat( 100, SDL_DEFAULT_REPEAT_INTERVAL ) ) ) { fprintf( stderr, "Setting keyboard repeat failed: %s\n", SDL_GetError( ) ); Quit( 1 ); } /* initialize OpenGL */ if ( initGL( ) == FALSE ) { fprintf( stderr, "Could not initialize OpenGL.\n" ); Quit( 1 ); } /* resize the initial window */ resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT ); /* wait for events */ while ( !done ) { /* handle the events in the queue */ while ( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_ACTIVEEVENT: /* Something's happend with our focus * If we lost focus or we are iconified, we * shouldn't draw the screen */ if ( event.active.gain == 0 ) isActive = FALSE; else isActive = TRUE; break; case SDL_VIDEORESIZE: /* handle resize event */ surface = SDL_SetVideoMode( event.resize.w, event.resize.h, 16, videoFlags ); if ( !surface ) { fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) ); Quit( 1 ); } resizeWindow( event.resize.w, event.resize.h ); break; case SDL_KEYDOWN: /* handle key presses */ handleKeyPress( &event.key.keysym ); break; case SDL_QUIT: /* handle quit requests */ done = TRUE; break; default: break; } } /* draw the scene */ if ( isActive ) drawGLScene( ); } /* clean ourselves up and exit */ Quit( 0 ); /* Should never get here */ return( 0 ); }
SdlOpenGlApplication::SdlOpenGlApplication(int width, int height) { initSDL(width,height,"Alpha"); initGL(width,height); _graphicsEngine = new SDLGLGraphicsEngine(width, height); }
//show the window void show(int argc, std::string argv) { initMainwnd(argc , argv); initGL(); glutMainLoop(); }
int main(int argc, char** argv) { initGL(); std::string x = getOpenGLState(false); debugPrintf("%s\n", x.c_str()); bool _endProgram = false; // Main loop do { // Event handling SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: _endProgram = true; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_ESCAPE: _endProgram = true; break; // TODO: Add other key handlers } break; // TODO: Add other event handlers } } glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glFrustum(-1, 1, -1, 1, -2, 2); // TODO: Your rendering code goes here; replace the simple triangle below. // Use getWindowHDC() if you want to make some kind of Win32 call static double angle = 0; angle += .01; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(angle, 0, 0, 1); glBegin(GL_TRIANGLES); glColor (Color3::BLUE); glVertex(Vector3(-0.5, -0.5, -1.0)); glVertex(Vector3( 0.5, -0.5, -1.0)); glColor (Color3::YELLOW); glVertex(Vector3( 0.0, 0.5, -1.0)); glEnd(); SDL_GL_SwapBuffers(); } while (! _endProgram); SDL_Quit(); return 0; }