예제 #1
0
void raytracer_app::load_shaders()
{
	GLuint      shaders[2];

	shaders[0] = load("shaders/trace-prepare.vs.glsl", GL_VERTEX_SHADER);
	shaders[1] = load("shaders/trace-prepare.fs.glsl", GL_FRAGMENT_SHADER);

	if (prepare_program != 0)
		glDeleteProgram(prepare_program);

	prepare_program = create_program(shaders, 2, true);

	// uniforms
	uniforms.ray_origin = glGetUniformLocation(prepare_program, "ray_origin");
	uniforms.ray_lookat = glGetUniformLocation(prepare_program, "ray_lookat");
	uniforms.aspect = glGetUniformLocation(prepare_program, "aspect");

	// trace program
	shaders[0] = load("shaders/raytracer.vs.glsl", GL_VERTEX_SHADER);
	shaders[1] = load("shaders/raytracer.fs.glsl", GL_FRAGMENT_SHADER);

	if (trace_program)
		glDeleteProgram(trace_program);

	trace_program = create_program(shaders, 2, true);

	shaders[0] = load("shaders/blit.vs.glsl", GL_VERTEX_SHADER);
	shaders[1] = load("shaders/blit.fs.glsl", GL_FRAGMENT_SHADER);

	if (blit_program)
		glDeleteProgram(blit_program);

	blit_program = create_program(shaders, 2, true);
}
예제 #2
0
static void
init_programs()
{
	create_program(&prog_f, "");
	create_program(&prog_i, "i");
	create_program(&prog_u, "u");
}
예제 #3
0
파일: renderman.c 프로젝트: fscz/gre
static int setup_program(SceneData* sceneData, SceneObject* so, SoData* soData, GLuint* programHandle) {

  GLuint vShaderHandle;
  GLuint fShaderHandle;
  if ( -1 == setup_shaders( sceneData, so, soData, &vShaderHandle, &fShaderHandle ) ) return -1;

  char progKey[KEYSIZE];
  snprintf (progKey, KEYSIZE, "%p,%p", &so->vShader, &so->fShader);

  GLuint program = (GLuint)hashmap_find(progKey, sceneData->mapShaderShader2Handle);  
  size_t programUsers;
  if (program) {

    *programHandle = program;
    programUsers = (size_t)hashmap_find ( progKey, sceneData->countProgramUsers );
    hashmap_insert ( progKey, (void*)(programUsers+1), sceneData->countProgramUsers );   
  } else {

    program = create_program( so->vShader, so->fShader, vShaderHandle, fShaderHandle );
    if ( -1 == program ) return -1;
    
    list_add ( (void*)program, sceneData->listPrograms );
    hashmap_insert ( progKey, (void*)program, sceneData->mapShaderShader2Handle );
    hashmap_insert ( progKey, (void*)1, sceneData->countProgramUsers );
    
    *programHandle = program;
  }
  return 0;
}
예제 #4
0
fractal_t::fractal_t()
    : pos_(0.5, 0), scale_factor_(1)
{
#ifdef USE_CORE_OPENGL
   TwInit(TW_OPENGL_CORE, NULL);
#else
   TwInit(TW_OPENGL, NULL);
#endif
   // Определение "контролов" GUI
   TwBar *bar = TwNewBar("Parameters");
   TwDefine(" Parameters size='300 50' color='70 100 120' valueswidth=220 iconpos=topleft");

   TwAddButton(bar, "Fullscreen toggle", toggle_fullscreen_callback, NULL,
               " label='Toggle fullscreen mode' key=f");

   // Создание шейдеров
   vs_ = create_shader(GL_VERTEX_SHADER  , "shaders//fractal.glslvs");
   fs_ = create_shader(GL_FRAGMENT_SHADER, "shaders//fractal.glslfs");
   // Создание программы путём линковки шейдерова
   program_ = create_program(vs_, fs_);
   // Создание буфера с вершинными данными
   init_buffer();
   // Создание VAO
   init_vertex_array();
}
예제 #5
0
	RenderData() : program_object(create_program(vertex_shader(), fragment_shader()))
	{
		position_loc = glGetAttribLocation(program_object, "a_position");
		tex_coord_loc = glGetAttribLocation(program_object, "a_texCoord");
		sampler_loc = glGetUniformLocation(program_object, "s_texture");
		matrix_loc = glGetUniformLocation(program_object, "m_texMatrix");
	}
예제 #6
0
int init_resources() {
    /* Initialize the FreeType2 library */
    if (FT_Init_FreeType(&ft)) {
        fprintf(stderr, "Could not init freetype library\n");
        return 0;
    }

    /* Load a font */
    if (FT_New_Face(ft, "/Users/liesaweigert/ClionProjects/AR/assets/orange juice 2.0.ttf", 0, &face)) {
        fprintf(stderr, "Could not open font!\n");
        return 0;
    }

    program = create_program("/Users/liesaweigert/ClionProjects/AR/src/text.v.glsl", "/Users/liesaweigert/ClionProjects/AR/src/text.f.glsl");
    if(program == 0)
        return 0;

    attribute_coord = get_attrib(program, "coord");
    uniform_tex = get_uniform(program, "tex");
    uniform_color = get_uniform(program, "color");

    if(attribute_coord == -1 || uniform_tex == -1 || uniform_color == -1)
        return 0;

    // Create the vertex buffer object
    glGenBuffers(1, &vbo);

    return 1;
}
예제 #7
0
pj_status_t pjmedia_vid_dev_opengl_init_buffers(gl_buffers *glb)
{
    /* Attributes */
    GLint attribLocation[NUM_ATTRIBUTES] = { ATTRIB_VERTEX,
        ATTRIB_TEXTUREPOSITON };
    GLchar *attribName[NUM_ATTRIBUTES] = { "position", "texCoord" };
    
    if (!glb->direct ) {
    	glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH,
                                     &glb->rendBufW);
    	glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT,
                                     &glb->rendBufH);
    
    	glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                  GL_RENDERBUFFER, glb->rendBuf);
    	if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
            LOG("Unable to create frame buffer");
            return -1;
        }
    }
    
    create_program(vertSrc, fragSrc, NUM_ATTRIBUTES,
                   (const GLchar **)&attribName[0], attribLocation,
                   &glb->directProg);
    
    if (!glb->directProg) {
        LOG("Unable to create program");
        return -2;
    }
    
    return PJ_SUCCESS;
}
예제 #8
0
unsigned int create_program_link(unsigned int sdr0, ...)
{
	unsigned int prog, sdr;
	va_list ap;

	if(!(prog = create_program())) {
		return 0;
	}

	attach_shader(prog, sdr0);
	if(glGetError()) {
		return 0;
	}

	va_start(ap, sdr0);
	while((sdr = va_arg(ap, unsigned int))) {
		attach_shader(prog, sdr);
		if(glGetError()) {
			return 0;
		}
	}
	va_end(ap);

	if(link_program(prog) == -1) {
		free_program(prog);
		return 0;
	}
	return prog;
}
예제 #9
0
파일: tvm.c 프로젝트: soarpenguin/tinyvm
tvm_t* tvm_create(char* filename)
{
	tvm_t* vm = (tvm_t*)malloc(sizeof(tvm_t));
    	if(!vm)
        	return NULL;

	vm->pMemory = create_memory(MIN_MEMORY_SIZE);
    	if(!vm->pMemory) {
        	free(vm);
        	return NULL;
    	}

	vm->pProgram = create_program();
    	if(!vm->pProgram) {
       		destroy_memory(vm->pMemory);
        	free(vm);
        	return NULL;
    	}

	create_stack(vm->pMemory, MIN_STACK_SIZE);

	if(interpret_program(vm->pProgram, filename, vm->pMemory) != 0) {
		// avoid memory leak when the interpret_program failed!
		tvm_destroy(vm);
		return NULL;
	}

	//if(!vm || !vm->pMemory || !vm->pProgram) return NULL;
	
	return vm;
}
예제 #10
0
LG_HPROGRAM lg_create_program(LG_HFSM hFsm,
                              const LG_ProgramOptions* options)
{
  return trapWithRetval(
    [hFsm,options](){ return create_program(hFsm, options); },
    nullptr
  );
}
예제 #11
0
파일: Shader.cpp 프로젝트: tim099/GameTest
void Shader::LoadShader(const char* vertex,const char* fragment) {
    std::vector<GLuint>shaders;
    shaders.push_back(create_shader(vertex,GL_VERTEX_SHADER));
    shaders.push_back(create_shader(fragment,GL_FRAGMENT_SHADER));

    GLuint ProgramID=create_program(shaders);
    programID=ProgramID;
}
예제 #12
0
bool FontEngine::init() {
    if (FT_Init_FreeType(&library)) {
        INFO("FT_Init_FreeType");
        return 0;
    }

    program = create_program(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE);
    if (!program) {
        INFO("Didn't Create Program");
        return 0;
    }

    coord = get_attrib(program, "coord");
    uniform_tex = get_uniform(program, "tex");
    uniform_color = get_uniform(program, "color");
    if (coord < 0 || uniform_tex < 0 || uniform_color < 0) {
        INFO("attribs not properly allocated");
        return 0;
    }

    billboard_program = create_program(VERTEX_SHADER_FILE_BILLBOARD, FRAGMENT_SHADER_FILE_BILLBOARD);
    if (!billboard_program) {
        INFO("Didn't Create BillBoard Program");
        return 0;
    }    

    billboard_pos = get_attrib(billboard_program, "position");
    billboard_coord = get_attrib(billboard_program, "texcoord");
    billboard_uniform_tex = get_uniform(billboard_program, "tex");
    billboard_uniform_color = get_uniform(billboard_program, "color");
    billboard_uniform_projection = get_uniform(billboard_program, "uProjection");
    billboard_uniform_view = get_uniform(billboard_program, "uView");
    
    
    if (billboard_pos < 0 || billboard_coord < 0|| billboard_uniform_tex < 0|| billboard_uniform_color< 0 || billboard_uniform_projection < 0 || billboard_uniform_view < 0) {
        INFO("billboard attribs not properly allocated");
        return 0;
        }

    glGenBuffers(1, &vbo);

    initialized = 1;
    return 1;
}
예제 #13
0
static void
render_triangle(struct nested_client *client, uint32_t time)
{
  static const GLfloat verts[3][2] = {
    { -0.5, -0.5 },
    {  0.5, -0.5 },
    {  0,    0.5 }
  };
  static const GLfloat colors[3][3] = {
    { 1, 0, 0 },
    { 0, 1, 0 },
    { 0, 0, 1 }
  };
  static GLfloat angle;
  GLfloat rotation[4][4] = {
    { 1, 0, 0, 0 },
    { 0, 1, 0, 0 },
    { 0, 0, 1, 0 },
    { 0, 0, 0, 1 }
  };

  if (client->program == 0)
    create_program(client, vertex_shader_text,
                   color_fragment_shader_text);

  angle += 0.1f;
  rotation[0][0] =  cos(angle);
  rotation[0][2] =  sin(angle);
  rotation[2][0] = -sin(angle);
  rotation[2][2] =  cos(angle);
  //  printf ("client: rotation: %.2f\n", angle);

  glClearColor(0.4, 0.4, 0.4, 1.0);
  glClear(GL_COLOR_BUFFER_BIT);

  glUseProgram(client->program);

  glViewport(0, 0, client->width, client->height);

  glUniformMatrix4fv(client->rotation, 1, GL_FALSE, (GLfloat *) rotation);

  glVertexAttribPointer(POS, 2, GL_FLOAT, GL_FALSE, 0, verts);
  glVertexAttribPointer(COL, 3, GL_FLOAT, GL_FALSE, 0, colors);
  glEnableVertexAttribArray(POS);
  glEnableVertexAttribArray(COL);

  glDrawArrays(GL_TRIANGLES, 0, 3);

  glDisableVertexAttribArray(POS);
  glDisableVertexAttribArray(COL);

  glFlush();
}
예제 #14
0
bool init_grid()
{
    grid_program = create_program(GRID_VERTEX_SHADER, GRID_FRAGMENT_SHADER);
    /* grid_position_attrib = glGetAttribLocation(grid_program, "position"); */
    /* grid_horizontal_attrib = glGetAttribLocation(grid_program, "horizontal"); */
    /* grid_vertex_attrib = glGetAttribLocation(grid_program, "vertex_pos"); */
    /* grid_transform_uniform = glGetUniformLocation(grid_program, "transform"); */
    /* grid_texture_uniform = glGetUniformLocation(grid_program, "texture"); */
    /* grid_color_uniform = glGetUniformLocation(grid_program, "color"); */
    /* if(checkGLError()) */
    /*     return false; */

    glGenBuffers(1, &grid_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, grid_buffer);
	glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), GRID_BUFFER_DATA, GL_STATIC_DRAW);
    if(checkGLError())
        return false;

    float position_buffer_data[TILEMAP_DIMS * 6];
    GLuint horiz_buffer_data[TILEMAP_DIMS * 2];

    for(int i = 0; i < TILEMAP_DIMS; ++i) {
        position_buffer_data[i*3] = i * 32;
        position_buffer_data[i*3 + 1] = 0;
        position_buffer_data[i*3 + 2] = -1;
        horiz_buffer_data[i] = 0;
    }

    for(int i = 0; i < TILEMAP_DIMS; ++i) {
        position_buffer_data[(TILEMAP_DIMS * 3) + (i*3)] = 0;
        position_buffer_data[(TILEMAP_DIMS * 3) + (i*3 + 1)] = i * 32;
        position_buffer_data[(TILEMAP_DIMS * 3) + (i*3 + 2)] = -1;
        horiz_buffer_data[(TILEMAP_DIMS) + i] = 1;
    }

    glGenBuffers(1, &grid_position_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, grid_position_buffer);
	glBufferData(GL_ARRAY_BUFFER, 6 * TILEMAP_DIMS * sizeof(float), position_buffer_data, GL_STATIC_DRAW);
    if(checkGLError())
        return false;


    glGenBuffers(1, &grid_horiz_buffer);
    glBindBuffer(GL_ARRAY_BUFFER, grid_horiz_buffer);
	glBufferData(GL_ARRAY_BUFFER, 2 * TILEMAP_DIMS * sizeof(GLuint), horiz_buffer_data, GL_STATIC_DRAW);
    if(checkGLError())
        return false;

    grid_dash_texture = create_texture_data(1, 5, GRID_TEXTURE_BUFFER_DATA);

    return true;
}
예제 #15
0
파일: tvm.c 프로젝트: fjrti/tinyvm
tvm_t* tvm_create(char* filename)
{
	tvm_t* vm = (tvm_t*)malloc(sizeof(tvm_t));

	vm->pMemory = create_memory(MIN_MEMORY_SIZE);
	vm->pProgram = create_program();

	create_stack(vm->pMemory, MIN_STACK_SIZE);

	if(!vm || !vm->pMemory || !vm->pProgram) return NULL;

	return vm;
}
예제 #16
0
int InitProgram() {
	programDepth = create_program("cube.v.glsl", "cube.f.glsl", vsDepth, fs);
	if (programDepth == 0)
		return 0;
	attribute_coord3d = get_attrib(programDepth, "vertex_position");
	attribute_normal = get_attrib(programDepth, "vertex_normal");
	attribute_colour = get_attrib(programDepth, "vertex_colour");

	uniform_m = get_uniform(programDepth, "model");
	uniform_v = get_uniform(programDepth, "view");
	uniform_p = get_uniform(programDepth, "projection");

	return 1;
}
예제 #17
0
int main(int argc, char **argv)
{
	glutInit(&argc, argv);

	dtx_set(DTX_PADDING, 64);

	if(!(font = dtx_open_font_glyphmap("regular.glyphmap")) ||
			dtx_get_glyphmap_ptsize(dtx_get_glyphmap(font, 0)) != FONT_SZ) {
		if(!(font = dtx_open_font("sans.ttf", 0))) {
			return 1;
		}
		dtx_prepare_range(font, FONT_SZ * SCALE_FACTOR, 32, 127);	/* printable ASCII range */
		dtx_resize_glyphmap(dtx_get_glyphmap(font, 0), 1, SCALE_FACTOR, DTX_LINEAR);
		dtx_save_glyphmap("regular.glyphmap", dtx_get_glyphmap(font, 0));
	}

	if(!(font_dist = dtx_open_font_glyphmap("distfield.glyphmap")) ||
			dtx_get_glyphmap_ptsize(dtx_get_glyphmap(font_dist, 0)) != FONT_SZ) {
		if(!(font_dist = dtx_open_font("sans.ttf", 0))) {
			return 1;
		}
		/* XXX use a large font size for the initial distance field generation
		 * then resize the resulting glyphmap to 1/8 of its size afterwards.
		 */
		dtx_prepare_range(font_dist, FONT_SZ * SCALE_FACTOR, 32, 127); /* printable ASCII range */
		dtx_calc_font_distfield(font_dist, 1, SCALE_FACTOR);
		dtx_save_glyphmap("distfield.glyphmap", dtx_get_glyphmap(font_dist, 0));
	}

	glutInitWindowSize(800, 600);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	glutCreateWindow("libdrawtext example: distance fields");

	glutDisplayFunc(disp);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keydown);
	glutKeyboardUpFunc(keyup);
	glutMouseFunc(mouse);
	glutMotionFunc(motion);

	glewInit();


	sdrprog = create_program(vsdr, psdr);
	glUseProgram(sdrprog);
	uloc_soft = glGetUniformLocation(sdrprog, "softness");

	glutMainLoop();
	return 0;
}
예제 #18
0
void initialize(GLuint &vao) {
	// Use a Vertex Array Object
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);

	// 4 triangles to be rendered
	GLfloat vertices_position[24] = {
		0.0, 0.0,
		0.5, 0.0,
		0.5, 0.5,
		
		0.0, 0.0,
		0.0, 0.5,
		-0.5, 0.5,
		
		0.0, 0.0,
		-0.5, 0.0,
		-0.5, -0.5,		

		0.0, 0.0,
		0.0, -0.5,
		0.5, -0.5,
	};

	// Create a Vector Buffer Object that will store the vertices on video memory
	GLuint vbo;
	glGenBuffers(1, &vbo);

	// Allocate space and upload the data from CPU to GPU
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices_position), vertices_position, GL_STATIC_DRAW);	

	GLuint shaderProgram = create_program("shaders/vert.shader", "shaders/frag.shader");

	// Bind the output names from the fragment program
	glBindFragDataLocation(shaderProgram, 0, "out_color");

	// Get the location of the attributes that enters in the vertex shader
	GLint position_attribute = glGetAttribLocation(shaderProgram, "position");

	// Specify how the data for position can be accessed
	glVertexAttribPointer(position_attribute, 2, GL_FLOAT, GL_FALSE, 0, 0);

	// Enable the attribute
	glEnableVertexAttribArray(position_attribute);

	// Draw wireframe triangles:
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
예제 #19
0
ProgramData GameObject::load_program(const std::string &vertex_shader_file_name, const std::string &fragment_shader_file_name)
{
	std::vector<GLuint> shader_list;
	shader_list.push_back(load_shader(GL_VERTEX_SHADER, vertex_shader_file_name));
	shader_list.push_back(load_shader(GL_FRAGMENT_SHADER, fragment_shader_file_name));

	ProgramData program_data;
	program_data.program = create_program(shader_list);
	program_data.model_to_clip_mat_unif = glGetUniformLocation(program_data.program, "model_to_clip_matrix");
	program_data.normal_model_to_world_mat_unif = glGetUniformLocation(program_data.program, "normal_model_to_world_matrix");
	program_data.dir_to_light_unif = glGetUniformLocation(program_data.program, "dir_to_light");
	program_data.light_intensity_unif = glGetUniformLocation(program_data.program, "light_intensity");
	program_data.ambient_intensity_unif = glGetUniformLocation(program_data.program, "ambient_intensity");
	return program_data;
}
예제 #20
0
파일: opengl.cpp 프로젝트: ammen99/wayfire
    void init()
    {
        render_begin();

        // enable_gl_synchronuous_debug()
        std::string shader_path = INSTALL_PREFIX "/share/wayfire/shaders";
        program.id = create_program(
            shader_path + "/vertex.glsl", shader_path + "/frag.glsl");

        program.mvpID      = GL_CALL(glGetUniformLocation(program.id, "MVP"));
        program.colorID    = GL_CALL(glGetUniformLocation(program.id, "color"));
        program.position   = GL_CALL(glGetAttribLocation(program.id, "position"));
        program.uvPosition = GL_CALL(glGetAttribLocation(program.id, "uvPosition"));

        render_end();
    }
예제 #21
0
// create_cpu will initialize the cpu and allocate enough memory.
cpu* create_cpu() {
    
    // Allocate Memory.
    cpu* local_cpu = (cpu*)malloc(sizeof(cpu));
    
    // Allocate / Create a new stack. (priority stack)
    local_cpu->stack = (stack*)create_stack();
    
    local_cpu->program = (program*)create_program();
    
    local_cpu->registers = (registers*)create_registers();
    
    local_cpu->num_registers = 8;
    
    // Reset Registers & Stack.
    reset_cpu(local_cpu);
    return local_cpu;
}
예제 #22
0
static void capture_init() {
  int i;
  for (i = 0; i < 10; i++) {
    glGenTextures(1, &texids[i]);
    glBindTexture(GL_TEXTURE_2D, texids[i]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1280, 720, 0, GL_RGBA,
                 GL_UNSIGNED_BYTE, 0);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  }
  progid = create_program(vertShader, fragShader);

  pixelbuffer = (char *)memalign(4096, 1280 * 720 * 4);

  frame = 0;
}
예제 #23
0
파일: shader.c 프로젝트: gfphoenix/seal2d
static void shader_load_all(struct shader* self) {
    const char* shaders[] = {
        "res/shaders/color.vert",
        "res/shaders/color.frag",
        
        "res/shaders/text.vert",
        "res/shaders/text.frag",
    };
    
    int n = sizeof(shaders)/sizeof(const char*)/2;
    for (int i = 0; i < n; ++i) {
        int index = i*2;
        GLuint vs = craete_shader_from_file(GL_VERTEX_SHADER, shaders[index]);
        GLuint fs = craete_shader_from_file(GL_FRAGMENT_SHADER, shaders[index+1]);
        
        GLuint program = create_program(vs, fs);
        self->shader_programs[i] = program;
    }
}
예제 #24
0
// the function we use to initialize opengl and the world
static int init_resources(){
	started = false;
	shaderProgram = create_program("frig.vert","frig.frag");

	if(!shaderProgram)
		return 0;

	attribute_coord = get_attrib(shaderProgram, "coord");
	uniform_mvp = get_uniform(shaderProgram, "mvp");
	uniform_sampler = get_uniform(shaderProgram, "texture");

	if(attribute_coord == -1 || uniform_mvp == -1)
		return 0;

	if(ui::text::init_text()){
		std::cerr << "Could not initialize fonts!" << std::endl;
		return 0;
	}

	glEnableVertexAttribArray(attribute_coord);

	cameraPos = glm::vec3(32.0,64.0,32.0);
	cameraRot = glm::vec3(0,0,0);

	// GENERATE HERE
	sc = new SuperChunk();


	blockTexture = Texture::loadTexture("assets/blockStrip.png");

	glUseProgram(shaderProgram);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,blockTexture);
	glUniform1f(uniform_sampler,0);

	glPolygonOffset(1, 1);
	
	glClearColor(0.6, 0.8, 1.0, 0.0);

	return 1;
}
예제 #25
0
파일: render.c 프로젝트: jtsymon/spacescape
void render_init() {
    render_gen_framebuffers();
    
    static const GLfloat fullscreen_quad[] = {
        -1.0f, -1.0f, 0.0f,
        1.0f, -1.0f, 0.0f,
        -1.0f, 1.0f, 0.0f,
        -1.0f, 1.0f, 0.0f,
        1.0f, -1.0f, 0.0f,
        1.0f, 1.0f, 0.0f,
    };

    glGenBuffers(1, &quad_vertexbuffer);
    glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof (fullscreen_quad), fullscreen_quad, GL_STATIC_DRAW);
    
    glGenVertexArrays(1, &VertexArrayID);
    glBindVertexArray(VertexArrayID);
    
    vect_passthrough = create_shader("shaders/pass_through.vert", GL_VERTEX_SHADER);
    frag_starfield = create_shader("shaders/starfield.frag", GL_FRAGMENT_SHADER);
    frag_star = create_shader("shaders/star.frag", GL_FRAGMENT_SHADER);
    frag_nebula1 = create_shader("shaders/nebula1.frag", GL_FRAGMENT_SHADER);
    frag_nebula2 = create_shader("shaders/nebula2.frag", GL_FRAGMENT_SHADER);
    frag_sun = create_shader("shaders/sun.frag", GL_FRAGMENT_SHADER);
    frag_screen = create_shader("shaders/screen.frag", GL_FRAGMENT_SHADER);
    
    program_starfield = create_program(vect_passthrough, frag_starfield);
    program_star = create_program(vect_passthrough, frag_star);
    program_nebula1 = create_program(vect_passthrough, frag_nebula1);
    program_nebula2 = create_program(vect_passthrough, frag_nebula2);
    program_sun = create_program(vect_passthrough, frag_sun);
    program_screen = create_program(vect_passthrough, frag_screen);
    
    glDeleteShader(vect_passthrough);
    glDeleteShader(frag_starfield);
    glDeleteShader(frag_star);
    glDeleteShader(frag_nebula1);
    glDeleteShader(frag_nebula2);
    glDeleteShader(frag_sun);
}
View::View(UAUiWindow* surface) 
        : surface(surface),
          rotation_angle(0.f),
          num_vertex(3)
{
    // assert(eglBindAPI(EGL_OPENGL_ES_API) == EGL_TRUE);
    egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    assert(egl_display != EGL_NO_DISPLAY);
    EGLint major, minor;
    if (EGL_FALSE == eglInitialize(egl_display, &major, &minor))
    {
        printf("egl error: problem initializing.\n");
        exit(1);
    }
        
    EGLint attribs[] = 
            {
                EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
                EGL_NONE 
            };
    EGLint n;
    if (EGL_FALSE == eglChooseConfig(
        egl_display,
        attribs, 
        &egl_config,
        1, 
        &n))
    {
        printf("egl error: Cannot choose configuration.\n");
    }
    
    EGLint context_attribs[] = 
            { 
                EGL_CONTEXT_CLIENT_VERSION, 2, 
                EGL_NONE
            };

    egl_context = eglCreateContext(
        egl_display, 
        egl_config, 
        EGL_NO_CONTEXT, 
        context_attribs);

    assert(EGL_NO_CONTEXT != egl_context);

    EGLNativeWindowType nativeWindow = ua_ui_window_get_native_type(surface);
    egl_surface = eglCreateWindowSurface(egl_display, egl_config, nativeWindow, NULL);

    eglMakeCurrent(
        egl_display,
        egl_surface,
        egl_surface,
        egl_context);

    vertex_data = triangle();
    color_data = color_triangle();
    
    gProgram = create_program(vertex_shader(), fragment_shader());
    if (!gProgram)
    {
        printf("error making program\n");
        return;
    }
    
    gvPositionHandle = glGetAttribLocation(gProgram, "vPosition");
    gvColorHandle = glGetAttribLocation(gProgram, "vColor");
    
    rotation_uniform = glGetUniformLocation(gProgram, "angle");
    
    return;
}
void
piglit_init(int argc, char**argv)
{
	GLuint ms_fbo, ms_rb;
	GLuint ss_fbo, ss_rb;
	GLuint programs[N_SAMPLES];
	bool use_uniform = false;
	GLuint shader_id_location = -1;
	GLfloat results[N_SAMPLES][2];
	bool pass = true;
	int i, j;

	for (i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "uniform")) {
			use_uniform = true;
		} else {
			fprintf(stderr, "unknown argument \"%s\"\n", argv[i]);
			piglit_report_result(PIGLIT_FAIL);
		}
	}

	piglit_require_extension("GL_ARB_gpu_shader5");
	piglit_require_GLSL_version(150);

	if (use_uniform) {
		programs[0] = create_program(-1);
		glUseProgram(programs[0]);
		shader_id_location = glGetUniformLocation(programs[0],
							  "sample_id");
	} else {
		for (i = 0; i < N_SAMPLES; i++)
			programs[i] = create_program(i);
	}

	create_framebuffer(N_SAMPLES,
			   &ms_fbo, &ms_rb);
	create_framebuffer(1, /* sample_count */
			   &ss_fbo, &ss_rb);

	glViewport(0, 0, 1, 1);

	for (i = 0; i < N_SAMPLES; i++) {
		if (use_uniform)
			glUniform1i(shader_id_location, i);
		else
			glUseProgram(programs[i]);

		glBindFramebuffer(GL_FRAMEBUFFER, ms_fbo);
		glClear(GL_COLOR_BUFFER_BIT);
		piglit_draw_rect_tex(-1, -1, 2, 2,
				     0, 0, 1, 1);

		glBindFramebuffer(GL_READ_FRAMEBUFFER, ms_fbo);
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, ss_fbo);

		glClear(GL_COLOR_BUFFER_BIT);
		glBlitFramebuffer(0, 0, /* srcX/Y0 */
				  1, 1, /* srcX/Y1 */
				  0, 0, /* dstX/Y0 */
				  1, 1, /* dstX/Y1 */
				  GL_COLOR_BUFFER_BIT,
				  GL_NEAREST);

		glBindFramebuffer(GL_FRAMEBUFFER, ss_fbo);

		glReadPixels(0, 0, /* x/y */
			     1, 1, /* width/height */
			     GL_RG, GL_FLOAT,
			     results[i]);
	}

	for (i = 0; i < N_SAMPLES; i++) {
		printf("value at sample %i = %f %f\n",
		       i,
		       results[i][0],
		       results[i][1]);
	}

	/* Check that the samples are within [0, 1] */
	for (i = 0; i < N_SAMPLES; i++) {
		if (results[i][0] < 0.0f || results[i][0] > 1.0f ||
		    results[i][1] < 0.0f || results[i][1] > 1.0f) {
			fprintf(stderr,
				"results for sample %i are out of range\n",
				i);
			pass = false;
		}
	}

	/* Check that all of the samples are different */
	for (i = 1; i < N_SAMPLES; i++) {
		for (j = 0; j < i; j++) {
			if (results[i][0] == results[j][0] &&
			    results[i][1] == results[j][1]) {
				fprintf(stderr,
					"samples %i and %i have the same "
					"value\n",
					i, j);
				pass = false;
				break;
			}
		}
	}

	glDeleteFramebuffers(1, &ms_fbo);
	glDeleteRenderbuffers(1, &ms_rb);
	glDeleteFramebuffers(1, &ss_fbo);
	glDeleteRenderbuffers(1, &ss_rb);

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
예제 #28
0
파일: renderman.c 프로젝트: fscz/gre
int renderman_rendertask_setup(RenderContext* ctx) {

  if (EGL_TRUE != eglMakeCurrent(ctx->esContext->display, ctx->esContext->surface, ctx->esContext->surface, ctx->esContext->context)) return -1;

  SceneData* sceneData = alloc_scene_data ( ctx->scene );

  glViewport ( 0, 0, ctx->esContext->screenWidth, ctx->esContext->screenHeight );

  glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
  glPixelStorei (GL_PACK_ALIGNMENT, 1);

  glFrontFace(GL_CW);
  glCullFace(GL_BACK);

  glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

  glGenFramebuffers(2, sceneData->fbos);
  glGenRenderbuffers(1, sceneData->rbos);
  glGenTextures(2, sceneData->tbos);
  GLenum status;

  // FBO 0  
  glBindTexture(GL_TEXTURE_2D, sceneData->tbos[0]);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ctx->esContext->screenWidth, ctx->esContext->screenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  glBindTexture(GL_TEXTURE_2D, 0);

  // RBO 0
  glBindRenderbuffer(GL_RENDERBUFFER, sceneData->rbos[0]);
  glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, ctx->esContext->screenWidth, ctx->esContext->screenHeight);
  glBindRenderbuffer(GL_RENDERBUFFER, 0);  

  glBindFramebuffer(GL_FRAMEBUFFER, sceneData->fbos[0]);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sceneData->tbos[0], 0);
  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, sceneData->rbos[0]);

  status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  if ( GL_FRAMEBUFFER_COMPLETE != status ) {
    log_message ("error: could not set up gbuffer");
    return -1;
  }  

  // FBO 1 
  glBindTexture(GL_TEXTURE_2D, sceneData->tbos[1]);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ctx->esContext->screenWidth, ctx->esContext->screenHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  glBindTexture(GL_TEXTURE_2D, 0);

  glBindFramebuffer(GL_FRAMEBUFFER, sceneData->fbos[1]);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, sceneData->tbos[1], 0);
  
  status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
  if ( GL_FRAMEBUFFER_COMPLETE != status ) {
    log_message ("error: could not set up light buffer");
    return -1;
  }


  // compile static shaders
  GLuint vHandle;
  GLuint fHandle;
  GLuint pHandle;
  
  if ( -1 == compile_shader ( GL_VERTEX_SHADER, vGShader, &vHandle ) ) return -1;
  hashmap_insert( "vGShader", (void*)vHandle, staticShaders );
  
  if ( -1 == compile_shader ( GL_FRAGMENT_SHADER, fGShader, &fHandle ) ) return -1;
  hashmap_insert( "fGShader", (void*)fHandle, staticShaders );

  pHandle = create_program (vGShader, fGShader, vHandle, fHandle);
  if ( -1 == pHandle ) return -1;
  hashmap_insert( "gbuffer", (void*)pHandle, staticPrograms );

  glBindFramebuffer(GL_FRAMEBUFFER, 0);

  int i;
  SceneObject* so;
  for ( i = list_size ( ctx->scene->initialObjects ) - 1; i >= 0; i-- ) {

    so = list_get ( i, ctx->scene->initialObjects );
    if ( -1 == setup_so ( sceneData, so ) ) {

      log_message ( "error setting up so. removing." );
      
      tear_down_so ( sceneData, so );

    } else {

      if ( (1 & so->stage) == 1) list_add( so, sceneData->stageGbuffer);
      if ( (2 & so->stage) == 2) list_add( so, sceneData->stageLight);
      if ( (4 & so->stage) == 4) list_add( so, sceneData->stageGeometry);
      if ( (8 & so->stage) == 8) list_add( so, sceneData->stageParticle);
      if ( (16 & so->stage) == 16) list_add( so, sceneData->stageOverlay);

    }
  }
  list_clear ( ctx->scene->initialObjects );
  
  return 0;
}
int main (void) {
  int *a;
  cl_mem a_in;
  cl_event event;
  cl_kernel kernel;
  cl_context context;
  cl_program program;
  cl_uint devices_num;
  char *program_source;
  cl_device_id device_id;
  cl_platform_id platform_id;
  cl_command_queue command_queue;

  program_source = (char *) calloc (1000, sizeof (char));
  program_source = readKernel ();

  /* number of platforms on the system */
  platforms_number ();

  /* id of the first platform proposed by the system */
  platform_id = get_platform ();

  /* number of devices on the platform specified by platform_id */
  devices_num = devices_number (platform_id);

  /* id of the first device proposed by the system on the platform
     specified by platform_id */
  device_id = create_device (platform_id);

  /* create a context to stablish a communication channel between the
     host process and the device */
  context = create_context (device_id);

  /* create a program providing the source code */
  program = create_program (context, program_source);

  /* compile the program for the specific device architecture */
  build_program (program, device_id);

  /* create a kernel given the program */
  kernel = create_kernel (program);

  /* create a memory object, in this case this will be an array of
     integers of length specified by the LENGTH macro */
  a = create_memory_object (LENGTH, "a");

  /* create a buffer, this will be allocated on the global memory of
     the device */
  a_in = create_buffer (LENGTH, context, "a_in");

  /* assign this buffer as the only kernel argument */
  set_kernel_argument (kernel, a_in, 0, "a_in");

  /* create a command queue, here we can enqueue tasks for the device
     specified by device_id */
  command_queue = create_command_queue (context, device_id);

  /* copy the memory object allocated on the host memory into the
     buffer created on the global memory of the device */
  enqueue_write_buffer_task (command_queue, a_in, LENGTH, a, "a_in");

  /* enqueue a task to execute the kernel on the device */
  event = enqueue_kernel_execution (command_queue, kernel, LENGTH, 0, NULL);
  enqueue_kernel_execution (command_queue, kernel, LENGTH, 1, &event);

  /* copy the content of the buffer from the global memory of the
     device to the host memory */
  enqueue_read_buffer_task (command_queue, a_in, LENGTH,  a, "a_in");

  /* print the memory object with the result of the execution */
  print_memory_object (a, LENGTH, "a");

  return 0;
}
예제 #30
0
파일: main.cpp 프로젝트: aaalexandrov/Alex
//------------------------------------------------------------------------------
int main(int argc, char** argv) {
//GRAPHICS SETUP
    glfwSetErrorCallback(error_callback);

    if(!glfwInit()) {
        std::cerr << "ERROR - glfwInit" << std::endl;
        exit(EXIT_FAILURE);
    }

    GLFWwindow* window = glfwCreateWindow(800, 600,
                                          "Ray 1!", NULL, NULL);
    if (!window) {
        std::cerr << "ERROR - glfwCreateWindow" << std::endl;
        glfwTerminate();
        exit(EXIT_FAILURE);
    }


    glfwSetKeyCallback(window, key_callback);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

    glfwMakeContextCurrent(window);

    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);

    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    std::cout << "GLSL version: "
              << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
    std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;


//GEOMETRY
    //geometry: textured quad
    float quad[] = {-1.0f,  1.0f, 0.0f, 1.0f,
                    -1.0f, -1.0f, 0.0f, 1.0f,
                     1.0f, -1.0f, 0.0f, 1.0f,
                     1.0f, -1.0f, 0.0f, 1.0f,
                     1.0f,  1.0f, 0.0f, 1.0f,
                    -1.0f,  1.0f, 0.0f, 1.0f};

    float  texcoord[] = {0.0f, 1.0f,
                         0.0f, 0.0f,
                         1.0f, 0.0f,
                         1.0f, 0.0f,
                         1.0f, 1.0f,
                         0.0f, 1.0f};
    //OpenGL >= 3.3 core requires a vertex array object containing multiple attribute
    //buffers
    GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);

    //geometry buffer
    GLuint quadvbo;
    glGenBuffers(1, &quadvbo);
    glBindBuffer(GL_ARRAY_BUFFER, quadvbo);
    glBufferData(GL_ARRAY_BUFFER, 6 * 4 * sizeof(float),
                 &quad[0], GL_STATIC_DRAW);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);

    //texture coordinate buffer
    GLuint texbo;
    glGenBuffers(1, &texbo);

    glBindBuffer(GL_ARRAY_BUFFER, texbo);
    glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(float),
                 &texcoord[0], GL_STATIC_DRAW);
    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glBindVertexArray(0);

//OPENGL RENDERING SHADERS

    GLuint glprogram = create_program(vertexShaderSrc, fragmentShaderSrc);

    //enable gl program
    glUseProgram(glprogram);

    //extract ids of shader variables
    GLint mvpID = glGetUniformLocation(glprogram, "MVP");
    assert(mvpID>=0);

    GLint textureID = glGetUniformLocation(glprogram, "cltexture");
    assert(textureID>=0);

    //beckground color
    glClearColor(0.0f, 0.0f, 0.4f, 1.0f);

    g_Backbuffer = std::make_shared<Backbuffer>();
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    framebuffer_size_callback(window, width, height);

//RENDER LOOP
    //rendering & simulation loop
    while (!glfwWindowShouldClose(window)) {
        // Clear the screen
        glClear(GL_COLOR_BUFFER_BIT);

        //setup OpenGL matrices
        const Eigen::Matrix4f modelView = Eigen::Matrix4f::Identity();
        const Eigen::Matrix4f MVP        = g_Backbuffer->m_Projection * modelView;

        glUniformMatrix4fv(mvpID, 1, GL_FALSE, MVP.data());

        //only need texture unit 0
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, g_Backbuffer->m_Texture);
        glUniform1i(textureID, 0);

        //select geometry to render
        glBindVertexArray(vao);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
        //draw
        glDrawArrays(GL_TRIANGLES, 0, 6);
        //unbind
        glBindVertexArray(0);
        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
        glBindTexture(GL_TEXTURE_2D, 0);
        //put pixels on screen
        glfwSwapBuffers(window);
        //query events
        glfwPollEvents();
    }

//CLEANUP
    glDeleteBuffers(1, &quadvbo);
    glDeleteBuffers(1, &texbo);
    glDeleteVertexArrays(1, &vao);

    g_Backbuffer.reset();

    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
    return 0;
}