示例#1
0
文件: main.c 项目: mdavidson/ogl
int main( int argc, char *argv[] )
{
    GLFWwindow* window;

    /*
    Setting error callback to receive any errors during
    initialization
    */
    glfwSetErrorCallback(error_callback);

    /*
    Initialize library
    */
    if( !glfwInit() ) {
        return( -1 );
        }

    /*
    Create a windowed mode window and its OpenGL context
    */
    window = glfwCreateWindow( WINDOW_WIDTH, WINDOW_HEIGHT, "Hello World", NULL, NULL );
    if( !window ) {
        glfwTerminate();
        return( -1 );
        }

    /*
    Make the window's context current
    */
    glfwMakeContextCurrent( window );

    /*
    Initialize game state
    */
    init_game_state( &game_ctrl );

    /*
    Set key callback to receive key events
    */
    glfwSetKeyCallback(window, key_callback);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        update_game_state( &game_ctrl );
        render_game( &game_ctrl );

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }
    
    glfwDestroyWindow(window);
    glfwTerminate();
    return( 0 );
}
示例#2
0
文件: st.c 项目: gattschardo/tetris
static void key_cb(SDL_Keycode k, int shift, struct game_state *gs)
{
	switch (k)
	{
	case SDLK_r: init_game_state(gs); break;
	case SDLK_q: if (shift) end_cb(gs); break;
	case SDLK_j:
	case SDLK_s: drop_block(gs); break;
	case SDLK_h:
	case SDLK_a: move_x(gs, -1); break;
	case SDLK_l:
	case SDLK_d: move_x(gs, 1); break;
	case SDLK_k:
	case SDLK_w: rot_block(gs); break;
	}

	draw_cb(gs);
}
示例#3
0
文件: st.c 项目: gattschardo/tetris
static struct game_state *init_window(int delay)
{
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);

	SDL_Window *screen = SDL_CreateWindow("Tetris",
		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, W_WIDTH, W_HEIGHT, 0);
	SDL_Renderer *r = SDL_CreateRenderer(screen, -1, 0);

	struct game_state *gs = malloc(sizeof(struct game_state));
	gs->surface = r;
	gs->delay = delay;
	gs->log = stdout;
	init_game_state(gs);

	/*
	g_timeout_add(10, (GSourceFunc) tick_cb, (gpointer) gs);
	*/

	return gs;
}