Beispiel #1
0
int main(int argc, char **argv) {
	if(init_socket() < 0) {
		perror("failed to init socket");
		return -1;
	}
	
	glutInitWindowSize(64, 60);
	
	/* initialize glut */
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutCreateWindow("Raadhus Shader");

	glutDisplayFunc(draw);
	glutIdleFunc(idle_func);
	glutKeyboardFunc(key_handler);
	glutMotionFunc(mouse_handler);
	
	if(read_shaders("shaders.conf")) {
		return EXIT_FAILURE;
	}

	set_shader(shaders[current_shader].prog);
	shader_activated_time = get_msec();

	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_DEPTH_TEST);

	init_osaa();

	glutMainLoop();
	return 0;
}
void init_ogl(struct ogl_state *ogl_state)
{
  ogl_state->script_lock = spin_lock_new(0);

  GLenum* types = malloc(sizeof(GLenum)*2);
  types[0] = GL_VERTEX_SHADER;
  types[1] = GL_FRAGMENT_SHADER;

  const char** srcs = read_shaders();

  /*malloc(2 * sizeof(char**));
  srcs[0] = vertex_shader_src;
  srcs[1] = fragment_shader_src;*/

  err_t status =
    init_shaders(ogl_state, 2, types, srcs);

  //offsetLocation = glGetUniformLocation(ogl_state->ogl_program, "offset");

  ///Init Vertex Buffer
  ogl_state->buffs = malloc(sizeof(struct ogl_buffer));
  ogl_state->num_buffs = 1;

  struct ogl_buffer *buff = ogl_state->buffs;

  buff->data =
    read_file_floats("data/floats.file", &buff->size);

  int i;
  /*printf("%i\n", buff->size);
  for (i = 0; i < buff->size; i++)
    printf("%f ", ((float*)(buff->data))[i]);
  printf("\n\n");*/
  buff->size *= sizeof(float);

  glGenBuffers(1, &positionBufferObject);

  glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
  glBufferData(GL_ARRAY_BUFFER, buff->size, buff->data, GL_STATIC_DRAW/*DYNAMIC*/);
  glBindBuffer(GL_ARRAY_BUFFER, 0);
  ///end

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

 //glViewport(0, 0, (GLsizei)1000, (GLsizei)1000);
}