bool ApplicationWindow_WGL::updateWindow(ulong timeSinceLastFrame)
	{
		MSG	msg;
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				_closePending = true;
				return false;
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}

		drawGLScene(timeSinceLastFrame);		
		SwapBuffers(_hDC);
		
	/*	if(drawGLScene())
		{
			SwapBuffers(_hDC);
		}
		else
		{	
			_closePending = true;
			return false;
		}*/

		return true;
	}
bool OpenGLGame::update()
{
	if ( !isActive() )						// 程序激活的么?
	{
		return true;
	}

	if ( isKeyPressed( VK_ESCAPE ) )				// ESC 按下了么?
	{
		return false;				// ESC 发出退出信号
	}

	// 不是退出的时候,刷新屏幕
	drawGLScene();				// 绘制场景
	::SwapBuffers( m_hDC );			// 交换缓存 (双缓存)

	processKeyEvent();

	if ( isKeyPressed( VK_F1 ) )					// F1键按下了么?
	{
		onKeyReleased( VK_F1 );			// 若是,使对应的Key数组中的值为 FALSE
		killGLWindow();					// 销毁当前的窗口
		m_bFullScreen = !m_bFullScreen; // 切换 全屏 / 窗口 模式

		// 重建 OpenGL 窗口
		if ( !createGLWindow() )
		{
			return false;				// 如果窗口未能创建,程序退出
		}
	}

	return true;
}
Пример #3
0
void CTorus::drawHapticScene(bool primary_context)
{
	hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, m_stiffness);
	hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, m_dampening);
	hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, m_static_friction);
	hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, m_dynamic_friction);
	if(primary_context)
		hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, m_shapeID);
	else
		hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, m_shapeID_1);
	drawGLScene();
	hlEndShape();
}
Пример #4
0
bool Sample_8_6::sendMessage(int message, int mode, int x, int y)
{
	switch (message) {
	case SDLK_o:
		m_fltrType = NONE;
		printf ("Original picture\n");
		break;
	case SDLK_h:
		m_fltrType = HORISONTAL;
		printf ("Inverted picture\n");
		break;
	case SDLK_v:
		m_fltrType = VERTICAL;
		printf ("Red channel of picture\n");
		break;
	case SDLK_l:
		m_fltrType = LAPLACIAN;
		printf ("Green channel of picture\n");
		break;
	case SDLK_EQUALS:
		m_bLoad = true;
		break;
	case SDLK_1:
		if (!m_bLoad)
			return false;
		m_image.loadBMP( "textures/pyramid.bmp" );
		break;
	case SDLK_2:
		if (!m_bLoad)
			return false;
		m_image.loadBMP( "textures/iceberg.bmp" );
		break;
	case SDLK_3:
		if (!m_bLoad)
			return false;
		m_image.loadBMP( "textures/forest.bmp" );
		break;
	default:
		m_bLoad = false;
		return false;
		break;
	}

	if (message != SDLK_EQUALS)
		m_bLoad = false;

	drawGLScene();
	return true;
}
Пример #5
0
static GF_Err droid_Flush(GF_VideoOutput *dr, GF_Window *dest)
{
	RAWCTX;
#ifdef DROID_EXTREME_LOGS
	LOG( ANDROID_LOG_VERBOSE, TAG, "Android Flush\n");
#endif /* DROID_EXTREME_LOGS */

#ifndef GLES_FRAMEBUFFER_TEST
	if ( rc->out_3d_type == 0 )
#endif
		drawGLScene(rc);
#ifdef DROID_EXTREME_LOGS
        LOG( ANDROID_LOG_VERBOSE, TAG, "Android Flush DONE");
#endif /* DROID_EXTREME_LOGS */
	return GF_OK;
}
Пример #6
0
/* function to handle key press events */
void handleKeyPress( SDL_keysym *keysym )
{
    switch ( keysym->sym )
        {
        case SDLK_ESCAPE:
            /* ESC key was pressed */
            Quit( 0 );
            break;
        case SDLK_F1:
            /* F1 key was pressed
             * this toggles fullscreen mode
             */
            SDL_WM_ToggleFullScreen( surface );
            break;
	case SDLK_KP_PLUS:
	    zoom += .1f;
	    resizeWindow(current_width, current_height);
	    drawGLScene();
	    break;
	case SDLK_KP_MINUS:
	    if (zoom > 1) {
  	        zoom -= .1f;
	        resizeWindow(current_width, current_height);
	    	drawGLScene();
            }
	    break;
	case SDLK_LEFT:
	    x_offset -= .1f;
	    resizeWindow(current_width, current_height);
	    drawGLScene();
	    break;
	case SDLK_RIGHT:
	    x_offset += .1f;
	    resizeWindow(current_width, current_height);
	    drawGLScene();
	    break;
	case SDLK_UP:
	    y_offset += .1f;
	    resizeWindow(current_width, current_height);
	    drawGLScene();
	    break;
	case SDLK_DOWN:
	    y_offset -= .1f;
	    resizeWindow(current_width, current_height);
	    drawGLScene();
	    break;

        default:
            break;
        }

    return;
}
Пример #7
0
// function to reset our viewport after a window resize
bool OGL_Application::resizeWindow( int width, int height )
{
	m_width = width;
	m_height = height;

	m_surface = SDL_SetVideoMode( m_width, m_height, m_bpp, m_videoFlags );
	if ( !m_surface )
	{
		fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );
		m_breakReason = SDL_VIDEORESIZE;
	}

	m_OGL_Consumer->reshape( m_width, m_height );

	drawGLScene();

	return true;
}
Пример #8
0
bool Sample_9_3::sendMessage(int message, int mode, int x, int y)
{
	switch (message) {
	case SDLK_s:
		m_drawSub = true;
		printf("Subtexture is drawn\n");
		break;
	case SDLK_r:
		m_drawSub = false;
		printf("Main texture is updated\n");
		break;
	default:
		return false;
		break;
	}

	drawGLScene();
	return true;
}
Пример #9
0
bool Sample_8_9::sendMessage(int message, int mode, int x, int y)
{
	switch (message) {
	case SDLK_s:
		m_sink = !m_sink;
		if (m_sink)
			printf("SINK\n");
		else
			printf("NO SINK\n");
		break;
	case SDLK_EQUALS:
		m_bLoad = true;
		break;
	case SDLK_1:
		if (!m_bLoad)
			return false;
		m_image.loadBMP( "textures/pagoda.bmp" );
		m_prevSink = !m_prevSink;
		break;
	case SDLK_2:
		if (!m_bLoad)
			return false;
		m_image.loadBMP( "textures/fish.bmp" );
		m_prevSink = !m_prevSink;
		break;
	case SDLK_3:
		if (!m_bLoad)
			return false;
		m_image.loadBMP( "textures/forest.bmp" );
		m_prevSink = !m_prevSink;
		break;
	default:
		m_bLoad = false;
		return false;
		break;
	}

	if (message != SDLK_EQUALS)
		m_bLoad = false;

	drawGLScene();
	return true;
}
Пример #10
0
bool Lesson_6_poly::sendMessage(int message, int mode, int x, int y)
{
	switch (message)
	{
	case SDLK_t:
		m_polySmooth = !m_polySmooth;
		if (m_polySmooth)
			printf ("Poly is smooth.\n");
		else
			printf ("Poly is not smooth.\n");
		break;
		drawGLScene();
	default:
		return false;
		break;
	}

	return true;
}
Пример #11
0
bool Lesson_7_1::sendMessage(int message, int mode, int x, int y)
{
	switch (message)
	{
	case SDLK_x:
		glRotatef(30.,1.0,0.0,0.0);
		break;
	case SDLK_y:
		glRotatef(30.,0.0,1.0,0.0);
		break;
	case SDLK_i:
		glLoadIdentity();
		gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
		break;
	default:
		return false;
		break;
	}

	drawGLScene();
	return true;
}
Пример #12
0
static int eventLoop(int videoFlags, SDL_Surface *surface)
{
    int done = FALSE;
    SDL_Event event;
	sState state;
	state.active = TRUE;
    state.quit = FALSE;

    /* wait for events */
    while(!state.quit)
	{
	    while(SDL_PollEvent(&event))
		{
			handleEvent(&event, &state, surface, videoFlags);
		}
        
	    if(state.active)
		{
            drawGLScene(&state);
		}
	}
}
Пример #13
0
bool Sample_9_4::sendMessage(int message, int mode, int x, int y)
{
	switch (message) {
	case SDLK_d:
		m_deep += 0.1;
		if(m_deep >= 1.1)
			m_deep = 0.0;
		printf("Texture deep is %.1f\n", m_deep);
		break;
	case SDLK_s:
		m_deep -= 0.1;
		if(m_deep < 0.0)
			m_deep = 1.0;
		printf("Texture deep is %.1f\n", m_deep);
		break;
	default:
		return false;
		break;
	}

	drawGLScene();
	return true;
}
Пример #14
0
void CCylinder::drawHapticScene(bool primary_context)
{
	hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, m_stiffness);
	hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, m_dampening);
	hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, m_static_friction);
	hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, m_dynamic_friction);

	if ( !m_customRendered )
	{
		if(primary_context)
			hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, m_shapeID);
		else
			hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, m_shapeID_1);

		drawGLScene();
		hlEndShape();
	}
	else
	{
		// Draw cylinder section
		if(primary_context)
			hlBeginShape(HL_SHAPE_CALLBACK, m_shapeID );
		else
			hlBeginShape(HL_SHAPE_CALLBACK, m_shapeID_1 );

		hlCallback(HL_SHAPE_INTERSECT_LS, 
			(HLcallbackProc) CHapticCylinder::intersectSurface, (void *) customCylinder);
		hlCallback(HL_SHAPE_CLOSEST_FEATURES, 
			(HLcallbackProc) CHapticCylinder::closestSurfaceFeatures, (void *) customCylinder);
		hlEndShape();

		// Draw disk A
		if(primary_context)
			hlBeginShape(HL_SHAPE_CALLBACK, diskAShape->GetShapeID () );
		else
			hlBeginShape(HL_SHAPE_CALLBACK, diskAShape->GetShapeID_1 ());

		diskATrans->makeIdentity ();

		diskATrans->multRight ( hduMatrix::createRotation ( 1, 0, 0, 0.5*PI ) );
		diskATrans->multRight ( hduMatrix::createTranslation ( 0, 0, 0.5 ) );

		diskATrans->multRight ( hduMatrix::createScale ( getSizeX(), getSizeY(), getSizeZ() ) );
		diskATrans->multRight ( getHduMatrix ( getRotation () ) );
		diskATrans->multRight ( hduMatrix::createTranslation ( getLocationX(), getLocationY(), getLocationZ () ) );

		hlCallback(HL_SHAPE_INTERSECT_LS, 
			(HLcallbackProc) CHapticDisk::intersectSurface, (void *) diskA);
		hlCallback(HL_SHAPE_CLOSEST_FEATURES, 
			(HLcallbackProc) CHapticDisk::closestSurfaceFeatures, (void *) diskA);
		hlEndShape();

		// Draw disk B
		if(primary_context)
			hlBeginShape(HL_SHAPE_CALLBACK, diskBShape->GetShapeID () );
		else
			hlBeginShape(HL_SHAPE_CALLBACK, diskBShape->GetShapeID_1 ());

		diskBTrans->makeIdentity ();

		diskBTrans->multRight ( hduMatrix::createRotation ( 1, 0, 0, -0.5*PI ) );
		diskBTrans->multRight ( hduMatrix::createTranslation ( 0, 0, -0.5 ) );

		diskBTrans->multRight ( hduMatrix::createScale ( getSizeX(), getSizeY(), getSizeZ() ) );
		diskBTrans->multRight ( getHduMatrix ( getRotation () ) );
		diskBTrans->multRight ( hduMatrix::createTranslation ( getLocationX(), getLocationY(), getLocationZ () ) );

		hlCallback(HL_SHAPE_INTERSECT_LS, 
			(HLcallbackProc) CHapticDisk::intersectSurface, (void *) diskB);
		hlCallback(HL_SHAPE_CLOSEST_FEATURES, 
			(HLcallbackProc) CHapticDisk::closestSurfaceFeatures, (void *) diskB);
		hlEndShape();
	}

}
Пример #15
0
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 );
	}

    /* initialize OpenGL */
    initGL( );

    /* 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 );
}
Пример #16
0
int main(int argc, char **argv)
{
    XEvent event;
    KeySym key;
    
    done = False;
    /* default to fullscreen */
    GLWin.fs = True;
    createGLWindow("NeHe's Rotation Tutorial", 1920, 1280, 24, GLWin.fs);

    /* wait for events*/ 
    while (!done)
    {
        /* handle the events in the queue */
        while (XPending(GLWin.dpy) > 0)
        {
            XNextEvent(GLWin.dpy, &event);
            switch (event.type)
            {
                case Expose:
	                if (event.xexpose.count != 0)
	                    break;
                    drawGLScene();
         	        break;
	            case ConfigureNotify:
	            /* call resizeGLScene only if our window-size changed */
	                if ((event.xconfigure.width != GLWin.width) || 
	                    (event.xconfigure.height != GLWin.height))
	                {
	                    GLWin.width = event.xconfigure.width;
	                    GLWin.height = event.xconfigure.height;
                        printf("Resize event\n");
	                    resizeGLScene(event.xconfigure.width,
	                        event.xconfigure.height);
	                }
	                break;
                /* exit in case of a mouse button press */
                case ButtonPress:
                    done = True;
                    break;
                case KeyPress:
                    key = XLookupKeysym(&event.xkey, 0);
                    keyPressed(key);
                    break;
                case ClientMessage:
                    if (*XGetAtomName(GLWin.dpy, event.xclient.message_type) == 
                        *"WM_PROTOCOLS")
                    {
                        printf("Exiting sanely...\n");
                        done = True;
                    }
                    break;
                default:
                    break;
            }
        }
        drawGLScene();
    }
    killGLWindow();
    return 0;
}
Пример #17
0
int sdl_main( router_t *prouter, tdata_t *ptdata, router_request_t *preq )
{
    router = prouter;
    tdata = ptdata;
    req = preq;

    /* 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 );
    }

    /* initialize OpenGL */
    initGL( );

    /* 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 );
                isActive = TRUE;
                break;
            case SDL_MOUSEBUTTONDOWN:
                {
                    int x = event.motion.x;
                    int y = event.motion.y;
                    GLdouble ox=0.0,oy=0.0,oz=0.0;
                    GLint viewport[4];
                    GLdouble modelview[16],projection[16];
                    GLfloat wx=x,wy,wz;
                    glGetIntegerv(GL_VIEWPORT,viewport);
                    y=viewport[3]-y;
                    wy=y;
                    glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
                    glGetDoublev(GL_PROJECTION_MATRIX,projection);
                    glReadPixels(x, y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&wz);
                    gluUnProject(wx,wy,wz,modelview,projection,viewport,&ox,&oy,&oz);


                    if (event.button.button == SDL_BUTTON_LEFT) {
                        GLfloat dist = 99999.0f;
                        uint32_t nearest = 0;

                        for (uint32_t i = 0; i < tdata->n_stops; i++) {
                            GLfloat cnt1 = lon2x_d(tdata->stop_coords[i].lon);
                            GLfloat cnt2 = lat2y_d(tdata->stop_coords[i].lat);

                            GLfloat cur_dist = ((ox - cnt1) * (ox - cnt1)) + ((oy - cnt2) * (oy - cnt2));

                            if (cur_dist < dist) {
                                dist = cur_dist;
                                nearest = i;
                            }
                        }

                        req->from = nearest;
                    } else if (event.button.button == 4) {

                        printf("%f %f %f %f\n", oy, y_offset, y2lat_d(oy), deltay);
                        x_offset = x2lon_d(ox);
                        y_offset = y2lat_d(oy);

                        zoom_level++;
                        zoom = pow(2, zoom_level);
                        perspective();
                    } else if (event.button.button == 5) {
                        if (zoom > 1) {
                            x_offset = x2lon_d(ox);
                            y_offset = y2lat_d(oy);

                            zoom_level--;
                            zoom = pow(2, zoom_level);
                            perspective();
                        }
                    }
                    break;
            }
            case SDL_QUIT:
                /* handle quit requests */
                done = TRUE;
                break;
            default:
                break;
            }
        }

        /* draw the scene */
        if ( isActive ) {
            router_request_next (req);

            router_route (router, req);
            //uint32_t n_reversals = req->arrive_by ? 1 : 2;
            //if (req->start_trip_trip != NONE) n_reversals = 0;
            //for (uint32_t i = 0; i < n_reversals; ++i) {
            //    router_request_reverse (router, req);
            //    router_route (router, req);
            //}

            drawGLScene( );
        }
    }

    /* clean ourselves up and exit */
    Quit( 0 );

    /* Should never get here */
    return( 0 );
}
Пример #18
0
int OGL_Application::exec()
{
	// the start Sample
	m_OGL_Consumer->setSample(m_curSample);
	SDL_WM_SetCaption(m_OGL_Consumer->getSampleName(), NULL);
	resizeWindow( INIT_W, INIT_H );

	// used to collect events
	SDL_Event event;

	// wait for events
	while ( !m_breakReason )
	{
		// 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 m_surface

				if ( event.active.gain == 0 )
					m_isActive = false;
				else
					m_isActive = true;
				break;
			case SDL_VIDEORESIZE:
				// handle resize m_event
				resizeWindow( event.resize.w, event.resize.h);
				break;
			case SDL_KEYDOWN:
				// handle key presses
				handleKeyPress( &event.key.keysym );
				break;
			case SDL_MOUSEBUTTONDOWN:
			case SDL_MOUSEBUTTONUP:
				m_OGL_Consumer->sendMessage(m_curSample, event.button.button, event.button.state,
						event.button.x, event.button.y);
				break;
			case SDL_MOUSEMOTION:
				m_OGL_Consumer->sendMessage(m_curSample, event.button.button, event.motion.state,
						event.motion.x, event.motion.y);
				break;
			case SDL_QUIT:
				// handle quit requests
				m_breakReason = SDL_QUIT;
				break;
			default:
				break;
			}
		}

		// draw the scene
		if ( m_isActive )
		{
			drawGLScene();
		}
	}

	if (m_breakReason == SDL_QUIT)
		m_breakReason = 0;

	return m_breakReason;
}
Пример #19
0
int main()
{
        // Create the main window
        sf::Window myWindow(sf::VideoMode(800, 600, 32), "SFML/NeHe OpenGL");

        initGL();
        resizeGLScene(800, 600);

        // Start game loop
        while (myWindow.isOpen())
        {
                // Process events
                sf::Event event;
                while (myWindow.pollEvent(event))
                {
                        // Close window : exit

                        switch (event.type) {
                                case sf::Event::Closed:
                                        myWindow.close();
                                        break;

                                // Resize event : adjust viewport
                                case sf::Event::Resized:
                                        resizeGLScene(event.size.width, event.size.height);
                                        break;

                                // Handle keyboard events
                                case sf::Event::KeyPressed:
                                        switch (event.key.code) {
                                                case sf::Keyboard::Escape:
                                                        myWindow.close();
                                                        break;

                                                case sf::Keyboard::F1:
                                                        fullscreen = !fullscreen;
                                                        myWindow.create(fullscreen ? sf::VideoMode::getDesktopMode() : sf::VideoMode(800, 600, 32),
                                                                        "SFML/NeHe OpenGL",
                                                                        (fullscreen ? sf::Style::Fullscreen : sf::Style::Resize | sf::Style::Close));

                                                        {
                                                                sf::Vector2u size = myWindow.getSize();
                                                                resizeGLScene(size.x,size.y);
                                                        }
                                                        break;

                                                case sf::Keyboard::F5:
                                                        vsync = !vsync;
                                                        break;
                                        }
                                        break;
                        }
                }

                // Turn VSYNC on so that animations run at a more reasonable speed on new CPU's/GPU's.
                myWindow.setVerticalSyncEnabled(vsync);

                // Set the active window before using OpenGL commands
                // It's useless here because active window is always the same,
                // but don't forget it if you use multiple windows or controls
                myWindow.setActive();

                //Draw some pretty stuff
                drawGLScene();

                // Finally, display rendered frame on screen
                myWindow.display();
        }

        return EXIT_SUCCESS;
}
Пример #20
0
int main( int argc, char **argv )
{
    /* Flags to pass to SDL_SetVideoMode */
    int videoFlags;
    /* main loop variable */
    bool 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 */
    bool isActive = true;
   	int bpp;
   	/* Audio */
	int audio_rate      = 22050;
	Uint16 audio_format = AUDIO_S16;
	int audio_channels  = 2;
	int audio_buffers   = 4096;

    /* initialize SDL */
    if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
	{
	    fprintf( stderr, "Video/Audio initialization failed: %s\n", SDL_GetError( ) );
	    Quit( 1 );
	}

	if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
	{
	    fprintf( stderr, "Unable to open audio!\n" );
	    Quit( 1 );
	}

	/* We're going to pre-load the sound effects that we need right here */
	Shot = Mix_LoadWAV("Data/Shot.wav");
	if(!Shot)
	{
    	fprintf( stderr, "Mix_LoadWAV: %s\n", Mix_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 */
   	bpp = videoInfo->vfmt->BitsPerPixel;
    surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, bpp, videoFlags );

    /* Verify there is a surface */
    if ( !surface )
	{
	    fprintf( stderr,  "Video mode set failed: %s\n", SDL_GetError( ) );
	    Quit( 1 );
	}

    /* initialize OpenGL */
	if (!initGL())
	{
	    fprintf( stderr,  "OpenGL initialization failed!\n");
	    Quit( 1 );
	}

    /* resize the initial window */
    resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT );
	
    /* Hides the cursor */
    SDL_ShowCursor(0);

    /* 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;
					lastTickCount = SDL_GetTicks();	// Get The Tick Count
				}
			    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;
			case SDL_MOUSEBUTTONDOWN:
				/* handle left click */
				if (event.button.button == SDL_BUTTON_LEFT)
				{
	            	mouse_x = event.button.x;
					mouse_y = event.button.y;
					Selection();
				}
				break;
			case SDL_MOUSEMOTION:			
				/* handle mouse movements */
	            mouse_x = event.motion.x;
				mouse_y = event.motion.y;
				break;			
			default:
			    break;
			}
		}

	    /* draw the scene */
	    if ( isActive && !done)
			drawGLScene();
	}

    /* clean ourselves up and exit */
    Quit( 0 );

    /* Should never get here */
    return( 0 );
}