Exemplo n.º 1
0
bool Engine_Init(char* windowTitle, int width, int height)
{
  window_width = width;
  window_height = height;

	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER) < 0)			// Initialize SDL2
		Engine_Quit("Unable to initialize SDL");		// Or die on error

  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

	// Create an application window with the following settings:
	window = SDL_CreateWindow(
		windowTitle,							//    window title
		SDL_WINDOWPOS_UNDEFINED,	//    initial x position
		SDL_WINDOWPOS_UNDEFINED,	//    initial y position
		width,									  //    width, in pixels
		height,									  //    height, in pixels
		SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
	);
  
	// Check that the window was successfully made
	if(window == NULL)
		Engine_Quit("Could not create window: %s");

	CheckSDLError(__LINE__);

	mainContext = SDL_GL_CreateContext(window);
  CheckSDLError(__LINE__);
	
	glewExperimental = GL_TRUE;
	glewInit();

  //Debug some things :)
  printf("Vendor: %s\n", glGetString(GL_VENDOR));
  printf("Renderer: %s\n", glGetString(GL_RENDERER));
  printf("Version: %s\n", glGetString(GL_VERSION));
  printf("GLSL: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
  printf("Extensions: %s\n", glGetString(GL_EXTENSIONS));

	// This makes our buffer swap syncronized with the monitor's vertical refresh
  SDL_GL_SetSwapInterval(1);

  // Create our renderer
	Render_Init(width, height);
  QuadRenderer::Resized(width, height);

	//Core loop
	nextTime = SDL_GetTicks() + TICK_INTERVAL;

	return true;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
	process_args(argc, argv);

	Camera_Reset();
	
	while (1) {

		if (glfwGetKey(mainWindow, GLFW_KEY_ESCAPE) == GLFW_PRESS ||
			glfwWindowShouldClose(mainWindow) == 1) {
			
			break;
		}

		process_inputs();

		Engine_UpkeepTime(); 	/* Updates deltaTime */
		Engine_Draw();		/* Render */
		Engine_Update();	/* Update anything else */

	}

	Engine_Quit();
	printf("\nKa3D is now shutting down!\n");
	return 0;
}