Example #1
0
void game_init(GameState* gs) {

  // Bind tiles vbo
  glGenBuffers(1, &gs->tiles_vbo);
  glBindBuffer(GL_ARRAY_BUFFER, gs->tiles_vbo);
  glBufferData(GL_ARRAY_BUFFER, sizeof(TILES_VBO)*sizeof(float), TILES_VBO, GL_STATIC_DRAW);

  gs->tiles_sheet = bitmap_load("bmp/tiles.bmp");
  gs->tiles_program = pipeline_new(
    shader_new(SHADER_VERTEX, "shader/tiles.vert"),
    shader_new(SHADER_FRAGMENT, "shader/tiles.frag"));

  pipeline_attribute(gs->tiles_program, "coord", 0);
  pipeline_attribute(gs->tiles_program, "st", 1);
  pipeline_uniform(gs->tiles_program, "pos", 0);
  pipeline_uniform(gs->tiles_program, "tex", 1);
  pipeline_uniform(gs->tiles_program, "tile", 2);

  // Bind player vbo
  glGenBuffers(1, &gs->player_vbo);
  glBindBuffer(GL_ARRAY_BUFFER, gs->player_vbo);
  glBufferData(GL_ARRAY_BUFFER, sizeof(PLAYER_VBO)*sizeof(float), PLAYER_VBO, GL_STATIC_DRAW);

  // load player spritesheet
  gs->player_spritesheet = bitmap_load("bmp/player.bmp");
  gs->player_x = gs->player_y = 0;
  gs->player_vx = gs->player_vy = 0;

  // create player render pipeline
  gs->player_program = pipeline_new(
    shader_new(SHADER_VERTEX, "shader/player.vert"),
    shader_new(SHADER_FRAGMENT, "shader/player.frag"));

  pipeline_attribute(gs->player_program, "coord", 0);
  pipeline_attribute(gs->player_program, "st", 1);
  pipeline_uniform(gs->player_program, "pos", 0);
  pipeline_uniform(gs->player_program, "tex", 1);
  pipeline_uniform(gs->player_program, "dir", 2);

  // Load audio stuff
  gs->bounce_sound = sound_load("sound/bounce.ogg");
  gs->ouch_sound = sound_load("sound/ouch.ogg");
  alGenSources(1, &gs->player_source);

  // Entity stuff
  gs->num_entities = 1;
  gs->ent[0].vbo = gs->player_vbo;
  gs->ent[0].spritesheet = gs->player_spritesheet;
  gs->ent[0].frame = 0;
  gs->ent[0].vx = gs->ent[0].vy = 8;
  gs->ent[0].x = gs->ent[0].y = 8;
  gs->ent[0].program = gs->player_program;
}
Example #2
0
void game_init(int* argc, char** argv, const char* title) {
  glutInit(argc, argv);
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
  glutInitWindowSize(800, 600);
  glutInitContextVersion(3, 1);
  glutInitContextProfile(GLUT_FORWARD_COMPATIBLE);
  glutInitContextProfile(GLUT_CORE_PROFILE);
  glutCreateWindow(title);
  glewExperimental = true;
  glewInit();

  glutKeyboardFunc(keyboard_down);
  glutKeyboardUpFunc(keyboard_up);
  glutSpecialFunc(keyboard_special_down);
  glutSpecialUpFunc(keyboard_special_up);
  glutCloseFunc(window_close);

  glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

  bodies = list_new();
  body_program = pipeline_new(
    shader_new(SHADER_VERTEX, "body.vert"),
    shader_new(SHADER_FRAGMENT, "body.frag"));

  glGenVertexArrays(1, &body_vao);
  glBindVertexArray(body_vao);

  pipeline_attribute(body_program, "coord", 0);
  pipeline_attribute(body_program, "color", 1);
}
Example #3
0
END_TEST

START_TEST (test_inspect_pipeline)
{
	pipeline *p;
	char *str;

	p = pipeline_new ();
	pipeline_command_args (p, "foo", "bar", NULL);
	pipeline_command_args (p, "grep", "baz", "quux", NULL);
	fail_unless (pipeline_get_ncommands (p) == 2);
	pipecmd_setenv (pipeline_get_command (p, 1), "KEY", "value");
	str = pipeline_tostring (p);
	fail_unless (!strcmp (str, "foo bar | KEY=value grep baz quux"));
	free (str);
	pipeline_free (p);
}
Example #4
0
File: filter.c Project: rcls/crap
void filter_changesets (database_t * db,
                        changeset_t ** serial, changeset_t ** serial_end,
                        const char * filter_command)
{
    // Set up a pipeline for running the subprocess and sending the data to it.
    struct filter_context context = { db, serial, serial_end };
    pipeline * pl = pipeline_new();
    pipeline_command (
        pl,
        pipecmd_new_function ("filter source", filter_output, NULL, &context));
    pipeline_command_argstr (pl, filter_command);
    pipeline_want_out (pl, -1);

    fflush (NULL);                      // We're forking...
    pipeline_start (pl);

    filter_input (db, pipeline_get_outfile (pl));

    int res = pipeline_wait (pl);
    if (res != 0)
        fatal ("filter subprocess gave error: %i\n", res);

    pipeline_free (pl);
}
static struct pipeline *create_pipeline(struct gles *gles, int argc,
					char *argv[], bool regenerate,
					struct framebuffer *source)
{
	struct framebuffer *target = NULL;
	struct geometry *plane, *output, *geometry;
	struct pipeline *pipeline;
	int i;

	pipeline = pipeline_new(gles);
	if (!pipeline)
		return NULL;

	/*
	 * FIXME: Keep a reference to the created geometry so that it can be
	 *        properly disposed of.
	 */
	plane = grid_new(0);
	if (!plane)
		return NULL;

	output = grid_new(subdivisions);
	if (!output)
		return NULL;

	if (transform)
		grid_randomize(output);

	for (i = 0; i < argc; i++) {
		struct pipeline_stage *stage = NULL;

		/*
		 * Render intermediate stages to a plane (2 triangles) geometry
		 * and the final one to a randomized grid to simulate geometric
		 * adaption.
		 */
		if (i >= argc - 1)
			geometry = output;
		else
			geometry = plane;

		/*
		 * FIXME: Keep a reference to the created target framebuffers
		 *        so that they can be properly disposed of.
		 */
		if (i < argc - 1) {
			target = framebuffer_new(gles->width, gles->height);
			if (!target) {
				fprintf(stderr, "failed to create framebuffer\n");
				goto error;
			}
		} else {
			target = display_framebuffer_new(gles->width, gles->height);
			if (!target) {
				fprintf(stderr, "failed to create display\n");
				goto error;
			}
		}

		if (strcmp(argv[i], "fill") == 0) {
			stage = simple_fill_new(gles, geometry, target,
						1.0, 0.0, 1.0);
			if (!stage) {
				fprintf(stderr, "simple_fill_new() failed\n");
				goto error;
			}
		} else if (strcmp(argv[i], "checkerboard") == 0) {
			stage = checkerboard_new(gles, geometry, target);
			if (!stage) {
				fprintf(stderr, "checkerboard_new() failed\n");
				goto error;
			}
		} else if (strcmp(argv[i], "clear") == 0) {
			stage = clear_new(gles, target, 1.0f, 1.0f, 0.0f);
			if (!stage) {
				fprintf(stderr, "clear_new() failed\n");
				goto error;
			}
		} else if (strcmp(argv[i], "copy") == 0) {
			stage = simple_copy_new(gles, geometry, source, target);
			if (!stage) {
				fprintf(stderr, "simple_copy_new() failed\n");
				goto error;
			}
		} else if (strcmp(argv[i], "copyone") == 0) {
			stage = copy_one_new(gles, geometry, source, target);
			if (!stage) {
				fprintf(stderr, "copy_one_new() failed\n");
				goto error;
			}
		} else if (strcmp(argv[i], "deinterlace") == 0) {
			stage = deinterlace_new(gles, geometry, source, target);
			if (!stage) {
				fprintf(stderr, "deinterlace_new() failed\n");
				goto error;
			}
		} else if (strcmp(argv[i], "cc") == 0) {
			stage = color_correct_new(gles, geometry, source,
						  target);
			if (!stage) {
				fprintf(stderr, "color_correct_new() failed\n");
				goto error;
			}
		} else {
			fprintf(stderr, "unsupported pipeline stage: %s\n",
				argv[i]);
			goto error;
		}

		/*
		 * Only add the generator to the pipeline if the regenerate
		 * flag was passed. Otherwise, render it only once.
		 */
		if (i > 0 || regenerate || argc == 1) {
			pipeline_add_stage(pipeline, stage);
		} else {
			stage->pipeline = pipeline;
			stage->render(stage);
			pipeline_stage_free(stage);
		}

		if (i < argc - 1)
			source = target;
	}

	return pipeline;

error:
	framebuffer_free(target);
	pipeline_free(pipeline);
	return NULL;
}
Example #6
0
void boot_init(int* argc, char** argv) {

  int error;

  fail_if(glfwInit() == false);

  // OpenGL version 3
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0);

  // No window resize
  glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, true);
  // 400% gameboy scale, 5 bit rgb with 1 bit alpha, 8 bit z buffer
  fail_if(glfwOpenWindow(160 * 4, 144 * 4, 5, 5, 5, 1, 8, 0, GLFW_WINDOW) == false);

  glfwSetWindowTitle("");

  glfwEnable(GLFW_AUTO_POLL_EVENTS); // Automatically poll input on swap
  glfwSwapInterval(1); // 0: vsync off, 1: vsync on 

  printf("Renderer: %s\n", glGetString(GL_RENDERER));
  printf("GL Version: %s\n", glGetString(GL_VERSION));
  printf("Using GLSL: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));

  error = glewInit();

  if (error != GLEW_OK) {
    fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(error));
  }

  printf("GL Extension Wrangler: %s\n", glewGetString(GLEW_VERSION));

  // Load audio
  fail_if(alutInit(argc, argv) == false);

  glClearColor(206.0/255.0, 230.0/255.0, 165.0/255.0, 1.0f);
  glEnable(GL_SCISSOR_TEST); // For geom culling
  
  // transparency
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // z-buffer
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);

  // Set up perspective
  glOrtho(0, 160, 144, 0, -1.0, 1.0);
  glDepthRange(-1.0f, 1.0f);
  glViewport(0, 0, 160 * 4, 144 * 4);

  // This is where Ill put the logo thing
  unsigned logo = bitmap_load("bmp/logo.bmp");
  unsigned logo_vbo;
  float t0, t1, dt;
  float logo_x = 16, logo_y = -80;
  float logo_v[] = {
    0,     0, 0, 1.0 - 0,
    0,   128, 0, 1.0 - 1,
    128, 128, 1, 1.0 - 1,
    128,   0, 1, 1.0 - 0,
  };

  glGenBuffers(1, &logo_vbo);
  glBindBuffer(GL_ARRAY_BUFFER, logo_vbo);
  glBufferData(GL_ARRAY_BUFFER, sizeof(logo_v)*sizeof(float), logo_v, GL_STATIC_DRAW);
 
  Pipeline* logo_program = pipeline_new(
    shader_new(SHADER_VERTEX, "shader/logo.vert"),
    shader_new(SHADER_FRAGMENT, "shader/logo.frag"));

  pipeline_attribute(logo_program, "coord", 0);
  pipeline_attribute(logo_program, "st", 1);
  pipeline_uniform(logo_program, "pos", 0);
  pipeline_uniform(logo_program, "tex", 1);

  glUseProgram(logo_program->id);

  // Bind the logo to texture 0
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, logo);
  glUniform1i(logo_program->uniform[1], 0);

  // Bind logo vbo
  glBindBuffer(GL_ARRAY_BUFFER, logo_vbo);
  glEnableVertexAttribArray(logo_program->attribute[0]);
  glVertexAttribPointer(logo_program->attribute[0], 2, GL_FLOAT, false, 4*sizeof(float), (void*)0);
  glEnableVertexAttribArray(logo_program->attribute[1]);
  glVertexAttribPointer(logo_program->attribute[1], 2, GL_FLOAT, false, 4*sizeof(float), (void*)(2 * sizeof(float)));

  // load sound
  unsigned sound_source;
  alGenSources(1, &sound_source);
  Sound* ding = sound_load("sound/ding.ogg");

  alSourcei(sound_source, AL_BUFFER, ding->buffer);
  
  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  glfwSwapBuffers();

  sleep(1);

  t0 = glfwGetTime();
  while (logo_y < 8) {
    t1 = glfwGetTime();
    dt = t1 - t0;
    t0 = t1;

    logo_y += 50 * dt;

    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    glUniform2f(logo_program->uniform[0], roundf(logo_x), roundf(logo_y));

    // Render logo
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    glfwSwapBuffers();
  }

  alSourcePlay(sound_source);

  glDisableVertexAttribArray(logo_program->attribute[0]);
  glDisableVertexAttribArray(logo_program->attribute[1]);

  sleep(1);
}