Example #1
0
int renderer_init_shaders(struct renderer *r)
{
	if (
		init_shader(
			&r->geom,
			"shader/geom_vert.glsl",
			"shader/geom_frag.glsl"
		) < 0
	)
	{
		fprintf(stderr, "Error initializing geometry shader\n");
		return -1;
	}
	if (
		init_shader(
			&r->null,
			"shader/null_vert.glsl",
			"shader/null_frag.glsl"
		) < 0
	)
	{
		fprintf(stderr, "Error initializing null shader\n");
		return -1;
	}
	if (
		init_shader(
			&r->light,
			"shader/light_vert.glsl",
			"shader/light_frag.glsl"
		) < 0
	)
	{
		fprintf(stderr, "Error initializing light shader\n");
		return -1;
	}
	if (
		init_shader(
			&r->negative,
			"shader/postprocess_vert.glsl",
			"shader/negative_frag.glsl"
		) < 0
	)
	{
		fprintf(stderr, "Error initializing negative shader\n");
		return -1;
	}
	if (
		init_shader(
			&r->textured,
			"shader/postprocess_vert.glsl",
			"shader/textured_frag.glsl"
		) < 0
	)
	{
		fprintf(stderr, "Error initializing textured shader\n");
		return -1;
	}

	return 0;
}
Example #2
0
void				Tiles::_initGlProgram(void)
{
	const char *const	vert_shader_code =
		"#version 410 core\n"
		"layout (location = 0) in vec2	pos;\n"
		"layout (location = 1) in vec3	col;\n"
		"out co { vec3					col;} vs_out;"
		"void main() { vs_out.col = col;"
		"gl_Position = vec4(pos, 0.f, 1.f); }\n";
	const char *const	frag_shader_code =
		"#version 410 core\n"
		"in co { vec3					col;} fs_in;"
		"out vec4 color;\n"
		"void main() { color = vec4(fs_in.col, 1.f); }\n";
	unsigned int		vs;
	unsigned int		fs;
	int					status;

	if ((_p = glCreateProgram()) == 0)
		throw std::domain_error("Cannot create program");
	vs = init_shader(GL_VERTEX_SHADER, vert_shader_code);
	fs = init_shader(GL_FRAGMENT_SHADER, frag_shader_code);
	glAttachShader(_p, vs);
	glAttachShader(_p, fs);
	glLinkProgram(_p);
	glDeleteShader(vs);
	glDeleteShader(fs);
	glGetProgramiv(_p, GL_LINK_STATUS, &status);
	if (status == 0)
	{
		glDeleteProgram(_p);
		throw std::domain_error("Error while linking shaders");
	}
	return ;
}
Example #3
0
static void init_shader_program()
{
  GLuint vertex_shader, fragment_shader;
  GLint program_ok;

  vertex_shader = init_shader(GL_VERTEX_SHADER, "shaders/vertex.glsl");
  fragment_shader = init_shader(GL_FRAGMENT_SHADER, "shaders/fragment.glsl");
  if (vertex_shader == 0 || fragment_shader == 0) {
    Log("Could not init shaders\n");
  }

  program = glCreateProgram();
  glAttachShader(program, vertex_shader);
  glAttachShader(program, fragment_shader);

  glLinkProgram(program);
  glGetProgramiv(program, GL_LINK_STATUS, &program_ok);
  if (!program_ok) {
    Log("Failed to link shader program.");
    Log("Vertex shader log: %s", get_shader_log(vertex_shader));
    Log("Fragment shader log: %s", get_shader_log(fragment_shader));
    Engine_print_program_log();
    glDeleteProgram(program);
  }
  glUseProgram(program);
}
static DFBBoolean
init_program(GLuint prog_obj,
             char *vert_prog_name, const char *vert_prog_src,
             char *frag_prog_name, const char *frag_prog_src,
             DFBBoolean texcoords)
{
     char *log;
     GLint status, log_length, char_count;

     if (!init_shader(prog_obj, vert_prog_src, GL_VERTEX_SHADER)) {
          D_ERROR("GLES2/Driver: %s failed to compile!\n", vert_prog_name);
          return DFB_FALSE;
     }

     if (!init_shader(prog_obj, frag_prog_src, GL_FRAGMENT_SHADER)) {
          D_ERROR("GLES2/Driver: %s failed to compile!\n", frag_prog_name);
          return DFB_FALSE;
     }

     // Bind vertex positions to "dfbPos" vertex attribute slot.
     glBindAttribLocation(prog_obj, GLES2VA_POSITIONS, "dfbPos");

     if (texcoords)
          // Bind vertex texture coords to "dfbUV" vertex attribute slot.
          glBindAttribLocation(prog_obj, GLES2VA_TEXCOORDS, "dfbUV");

     // Link the program object and check for errors.
     glLinkProgram(prog_obj);
     glValidateProgram(prog_obj);
     glGetProgramiv(prog_obj, GL_LINK_STATUS, &status);

     if (status) {
          // Don't need the shader objects anymore.
          GLuint  shaders[2];
          GLsizei shader_count;

          glGetAttachedShaders(prog_obj, 2, &shader_count, shaders);

          glDetachShader(prog_obj, shaders[0]);
          glDetachShader(prog_obj, shaders[1]);

          return DFB_TRUE;
     }
     else {
          // Report errors.  Shader objects detached when program is deleted.
          glGetProgramiv(prog_obj, GL_INFO_LOG_LENGTH, &log_length);
          log = D_MALLOC(log_length);

          glGetProgramInfoLog(prog_obj, log_length, &char_count, log);
          D_ERROR("GLES2/Driver: shader program link failure:\n%s\n", log);
          D_FREE(log);

          return DFB_FALSE;
     }

     glUseProgram( prog_obj );
}
Example #5
0
File: draw.cpp Project: janba/DSC
Painter::Painter(const vec3& light_pos)
{    
    // Initialize shader
    wire_shader = init_shader("shaders/gouraud.vert", "shaders/wire.frag", "fragColour", "shaders/wire.geom");
    line_shader = init_shader("shaders/line.vert", "shaders/line.frag", "fragColour", "shaders/line.geom");
    gouraud_shader = init_shader("shaders/gouraud.vert",  "shaders/gouraud.frag", "fragColour");
    
    // Send light position uniform to the shader
    glUseProgram(gouraud_shader);
    CGLA::Vec3f lp(light_pos);
    GLuint lightPosUniform = glGetUniformLocation(gouraud_shader, "lightPos");
    if (lightPosUniform == NULL_LOCATION) {
        std::cerr << "Shader did not contain the 'lightPos' uniform."<<std::endl;
    }
    glUniform3fv(lightPosUniform, 1, &lp[0]);
    
    glUseProgram(wire_shader);
    lightPosUniform = glGetUniformLocation(wire_shader, "lightPos");
    if (lightPosUniform == NULL_LOCATION) {
        std::cerr << "Shader did not contain the 'lightPos' uniform."<<std::endl;
    }
    glUniform3fv(lightPosUniform, 1, &lp[0]);
    
    CGLA::Vec4f wire_col(0.25,0.5,0.6, 1.);
    GLuint wireColUniform = glGetUniformLocation(wire_shader, "wireCol");
    if (wireColUniform == NULL_LOCATION) {
        std::cerr << "Shader did not contain the 'wireCol' uniform."<<std::endl;
    }
    glUniform4fv(wireColUniform, 1, &wire_col[0]);
    
    check_gl_error();
    
    interface = std::unique_ptr<GLObject>(new GLObject(gouraud_shader, {0.15f,0.4f,0.5f, 1.f}, {0.2f, 0.3f, 0.4f, 1.f}, {0.2f, 0.3f, 0.4f, 1.f}));
    wire_frame = std::unique_ptr<GLObject>(new GLObject(wire_shader, {0.15f,0.4f,0.5f, 1.f}, {0.2f, 0.3f, 0.4f, 1.f}, {0.2f, 0.3f, 0.4f, 1.f}));
    domain = std::unique_ptr<GLObject>(new GLObject(gouraud_shader, {0.1f, 0.1f, 0.3f, 1.f}, {0.2f, 0.2f, 0.3f, 1.f}, {0.f, 0.f, 0.f, 1.f}));
    low_quality = std::unique_ptr<GLObject>(new GLObject(gouraud_shader, {0.3f, 0.1f, 0.1f, 0.1f}, {0.6f, 0.4f, 0.4f, 0.2f}, {0.f, 0.f, 0.f, 0.f}));
    edges = std::unique_ptr<GLObject>(new GLObject(line_shader, {0.f,0.f,0.f, 1.f}, {0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}));
    unmoved = std::unique_ptr<GLObject>(new GLObject(line_shader, {0.2f, 0.2f, 0.7f, 1.f}, {0.f, 0.f, 0.f, 0.f}, {0.f, 0.f, 0.f, 0.f}));
    
    // Enable states
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    check_gl_error();
}
Example #6
0
bool ZZshStartUsingShaders() {

	ZZLog::Error_Log("Creating effects.");
	B_G(LoadEffects(), return false);
	if (!glCreateShader)
	{
		ZZLog::Error_Log("GLSL shaders is not supported, stop.");
		return false;
	}

	init_shader();

	// create a sample shader
	clampInfo temp;
	memset(&temp, 0, sizeof(temp));
	temp.wms = 3; temp.wmt = 3;

	// test
	bool bFailed;
	FRAGMENTSHADER* pfrag = ZZshLoadShadeEffect(0, 1, 1, 1, 1, temp, 0, &bFailed);
	if( bFailed || pfrag == NULL ) {
		return false;
		ZZLog::Error_Log("Shader test failed.");
	}

	ZZLog::Error_Log("Creating extra effects.");
	B_G(ZZshLoadExtraEffects(), return false);


	return true;
}
Example #7
0
	void Plane::init()
	{
		init_shader();
		init_buffer();
		init_vertexArray();
		init_texture();
	}
Example #8
0
void Torus::Init()
{
	init_buffer();
	init_vertexArray();
	init_shader();
	init_texture();
}
Example #9
0
void Cube::Init(ID3D11Device *pD3D11Device, ID3D11DeviceContext *pD3D11DeviceContext, HWND hWnd)
{
 
	init_buffer(pD3D11Device, pD3D11DeviceContext);
	init_shader(pD3D11Device, hWnd);
	init_texture(pD3D11Device);
}
Example #10
0
Shader* create_shader_from_filename(const std::string& filename) {
	std::vector<ShaderStage*> shader_list;
	{
		FileData file = load_file(filename + ".vert");
		shader_list.push_back(new ShaderStage(compile_shader(GL_VERTEX_SHADER, filename.c_str(), file.data())));
	}
	{
		FileData file = load_file(filename + ".frag");
		shader_list.push_back(new ShaderStage(compile_shader(GL_FRAGMENT_SHADER, filename.c_str(), file.data())));
	}

	for(ShaderStage* s : shader_list) {
		if(s->resource == 0) {
			std::for_each(shader_list.begin(), shader_list.end(), free_shaderstage);
			return nullptr;
		}
	}

	GLuint resource = link_program(filename.c_str(), shader_list);
	std::for_each(shader_list.begin(), shader_list.end(), free_shaderstage);

	if(resource == 0) return nullptr;

	Shader* shader = new Shader();
	shader->resource = resource;

	init_shader(shader);

	return shader;
}
Example #11
0
	void Triangle::init()
	{
	
		init_shader();
		init_buffer();
		init_vertexArray();
	}
Example #12
0
  application()
    : _program  (),
      _cube     (0, -1, 2, 1),
      _trackball(new gpucast::gl::trackball),
      _cubemap  (new gpucast::gl::cubemap)
  {
    init_shader();

    gpucast::gl::glutwindow::instance().add_eventhandler(_trackball);

    // bind draw loop
    std::function<void()> dcb = std::bind(&application::draw, std::ref(*this));
    gpucast::gl::glutwindow::instance().set_drawfunction(std::make_shared<std::function<void()>>(dcb));

    glEnable(GL_DEPTH_TEST);

    _cubemap->load( "./panorama_negative_x.jpg", 
                    "./panorama_positive_x.jpg", 
                    "./panorama_negative_y.jpg", 
                    "./panorama_positive_y.jpg", 
                    "./panorama_negative_z.jpg", 
                    "./panorama_positive_z.jpg");

    _cubemap->parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    _cubemap->parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  }
Example #13
0
void Rectangle::Init()
{
	init_buffer();
	init_vertexArray();
	init_shader();
	init_texture();
}
Example #14
0
void init()
{
	init_shader();
	float lpos[4] = {1, 0.5 , 1 ,0};
	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

}
Example #15
0
void init()
{
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

	init_shader();
	init_buffer();
	init_vertexArray();
}
Example #16
0
void TriangleApp::init()
{
	init_shader();
	init_buffer();
	init_vertexArray();
	init_texture();
	init_windowInfo();
}
Example #17
0
	void Cube::init()
	{
		init_viewport();
		init_shader();
		init_buffer();
		init_vertexArray();
	
	}
Example #18
0
void Instance::Init()
{
	init_buffer();
	init_vertexArray();
	init_shader();


}
Example #19
0
	void Asteroid::init()
	{
		m_LightGui.v_init();
		m_RotationGui.v_init();

		init_buffer();
		init_shader();
	}
Example #20
0
	void DebugWindow::Init(int depthWidth, int depthHeight)
	{
		glViewport(0, 0, depthWidth, depthHeight);

		init_buffer();
		init_vertexArray();
		init_shader();
	}
Example #21
0
	void Scene::Init()
	{
		init_buffer();
		init_vertexArray();
		init_shader();
		init_texture();
		oglDebug.Debug();
	}
void shadowmapping_app::v_Init()
{
    init_shader();

    int i;

    static const char * const object_names[] =
    {
        "../../../media/objects/dragon.sbm",
        "../../../media/objects/sphere.sbm",
        "../../../media/objects/cube.sbm",
        "../../../media/objects/cube.sbm",
        "../../../media/objects/cube.sbm",
    };

    static const vmath::vec4 object_colors[] =
    {
        vmath::vec4(1.0f, 0.7f, 0.8f, 1.0f),
        vmath::vec4(0.7f, 0.8f, 1.0f, 1.0f),
        vmath::vec4(0.3f, 0.9f, 0.4f, 1.0f),
        vmath::vec4(0.6f, 0.4f, 0.9f, 1.0f),
        vmath::vec4(0.8f, 0.2f, 0.1f, 1.0f),
    };

    for (i = 0; i < OBJECT_COUNT; i++)
    {
        objects[i].obj.load(object_names[i]);
        objects[i].diffuse_albedo = object_colors[i];
    }

    glGenFramebuffers(1, &depth_fbo);
    glBindFramebuffer(GL_FRAMEBUFFER, depth_fbo);

    glGenTextures(1, &depth_tex);
    glBindTexture(GL_TEXTURE_2D, depth_tex);
    glTexStorage2D(GL_TEXTURE_2D, 11, GL_DEPTH_COMPONENT32F, FBO_SIZE, FBO_SIZE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glGenTextures(1, &color_tex);
    glBindTexture(GL_TEXTURE_2D, color_tex);
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, FBO_SIZE, FBO_SIZE);

    glGenTextures(1, &temp_tex);
    glBindTexture(GL_TEXTURE_2D, temp_tex);
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA32F, FBO_SIZE, FBO_SIZE);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_tex, 0);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, color_tex, 0);

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    glEnable(GL_DEPTH_TEST);

    glGenVertexArrays(1, &quad_vao);
    glBindVertexArray(quad_vao);
}
Example #23
0
	void Plane::init()
	{

		m_LightGUI.v_init();

		init_buffer();
		init_vertexArray();
		init_shader();
		init_texture();
	}
Example #24
0
void Clip::init()
{
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CLIP_DISTANCE0);
	glEnable(GL_CLIP_DISTANCE1);

	init_buffer();
	init_vertexArray();
	init_shader();
}
Example #25
0
	void Scene::Init(int sw, int sh)
	{
		glEnable(GL_CULL_FACE);
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LESS);

		m_Aspect = static_cast<GLfloat>(sw) / sh;

		init_buffer();
		init_shader();
	}
Example #26
0
void initialize()
{
    void *host_addr = memalign(1024*1024,HOST_SIZE);
    void *main_addr = (void*)((u64)host_addr + CB_SIZE);

    init_spu();
    init_screen(host_addr,HOST_SIZE);
    init_shader();
    init_texture();
    init_memory(main_addr,(HOST_SIZE - CB_SIZE));
}
Example #27
0
void init_draw_model()
{
    load_model();
    init_shader();
    init_texture();

    const static unsigned int stride = sizeof(struct Vertex);
    glGenBuffers(1, &monster_vbo);
    glBindBuffer(GL_ARRAY_BUFFER, monster_vbo);
    glBufferData(GL_ARRAY_BUFFER, v_num*stride, v_array, GL_STATIC_DRAW);

}
Example #28
0
Shader* create_shader(const char* name, const std::vector<ShaderStage*>& stages) {
	GLuint resource = link_program(name, stages);

	if(resource == 0) return nullptr;

	Shader* shader = new Shader();
	shader->resource = resource;

	init_shader(shader);

	return shader;
}
Example #29
0
int main(int argc,const char *argv[])
{
	s32 ret,i;
	padInfo padinfo;
	padData paddata;
	void *host_addr = memalign(1024*1024,HOST_SIZE);

	printf("rsxtest started...\n");

	init_screen(host_addr,HOST_SIZE);
	ioPadInit(7);
	init_shader();
	init_texture();

	sphere = createSphere(3.0f,32,32);
	donut = createDonut(3.0f,1.5f,32,32);
	cube = createCube(5.0f);

	ret = atexit(program_exit_callback);
	ret = sysUtilRegisterCallback(0,sysutil_exit_callback,NULL);

	P = transpose(Matrix4::perspective(DEGTORAD(45.0f),aspect_ratio,1.0f,3000.0f));

	setTexture();
	setDrawEnv();
	setRenderTarget(curr_fb);

	running = 1;
	while(running) {
		ret = sysUtilCheckCallback();

		ioPadGetInfo(&padinfo);
		for(i=0; i<MAX_PADS; i++){
			if(padinfo.status[i]){
				ioPadGetData(i, &paddata);

				if(paddata.BTN_CROSS){
					return 0;
				}
			}

		}
		
		drawFrame();
		flip();
	}

	return 0;
}
Example #30
0
  application()
    : _program  (),
      _cube     (0, -1, 2, 1),
      _trackball(new gpucast::gl::trackball),
      _view_ubo(new gpucast::gl::uniformbuffer)
  {
    init_shader(); 

    gpucast::gl::glutwindow::instance().add_eventhandler(_trackball);

    // bind draw loop
    std::function<void()> dcb = std::bind(&application::draw, std::ref(*this));
    gpucast::gl::glutwindow::instance().set_drawfunction(std::make_shared<std::function<void()>>(dcb));

    _view_ubo->bufferdata(sizeof(matrix_layout), 0, GL_DYNAMIC_DRAW);

    glEnable(GL_DEPTH_TEST);
  }