示例#1
0
文件: main.c 项目: te-bachi/cgr
int main(int argc, char* argv[]) {
	// If intialising of SDL fails -> quit the program with error code 1
	if (!init_SDL()) {
		quit_program(1);
	}
	
	// If intialising of OpenGL fails -> quit the program with error code 1
	if (!init_OpenGL(default_width, default_height)) {
		quit_program(1);
	}
	
	// Repeat forever
	while(true) {
		// Draw your graphics
		draw_screen();
		
		// Process any ocuring events 
		process_events();
		fflush(stdout);
	}
	
	// You shouldn't get here. Only if someone changes the while condition...
	quit_program(0);
	
	return 0;
}
示例#2
0
Display* Display_init(char* title, unsigned int width, unsigned int height) {

    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        printf("Failed to initialize SDL\n");
        return NULL;
    }

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

    //SDL_GL_SetSwapInterval(0); // vsync off if driver allows

    SDL_Window* window = SDL_CreateWindow(
        title,
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        width,
        height,
        SDL_WINDOW_OPENGL
    );

    SDL_WarpMouseInWindow(
        window,
        (float) width / 2.f,
        (float) height / 2.f
    );

    //SDL_SetRelativeMouseMode(true); // grab mouse

    SDL_GLContext context = SDL_GL_CreateContext(window);

    Display* display = malloc(sizeof(Display));
    display->window = window;
    display->context = context;
    display->width = width;
    display->height = height;

    init_OpenGL(display);

    return display;
}