void display_gl_memory_init(struct display_gl_s* display) {
	location_t			location[] = {
		{"in_Position", 0},
		{"in_Value", 1},
		{NULL, 0}
	};
	int32 width = display->grid_width;
	int32 height = display->grid_height;
	int32 size = width * height;

	display->hex_texture = display_gl_load_texture(TEXTURE("hex.png"));

	display_gl_load_shader(&display->memory_shader, SHADER("memory.vert"), SHADER("memory.frag"), location);
	display->memory_uniform_projection_matrix = glGetUniformLocation(display->memory_shader.id, "uni_ProjectionMatrix");
	display->memory_uniform_coord = glGetUniformLocation(display->memory_shader.id, "uni_Coord");
	display->memory_uniform_color = glGetUniformLocation(display->memory_shader.id, "uni_Color");
	display->memory_uniform_texture = glGetUniformLocation(display->memory_shader.id, "uni_Texture");

	{
		float delta = 1.f / 255.f;
		float uv[] = {
			0.f, 0.f, delta, 0.f, 0.f, 1.0f, delta, 1.0f
		};
		int id = 0;
		glUseProgram(display->memory_shader.id);
		glUniform2fv(display->memory_uniform_coord, 4, uv);
		glUniform1iv(display->memory_uniform_texture, 1, &id);
		glUseProgram(0);
	}

	display->memory_vao = display_gl_create_vao();


	display->memory_vertex_buffer = display_gl_create_buffer(GL_ARRAY_BUFFER, (size + height) * 4, GL_STREAM_DRAW, NULL);
	display->memory_vertex_count = (size + height) * 4;
	display->memory_index_count = (size + height) * 6;
	display->memory_size = (size + height);
	display->memory_width = DISPLAY_CELL_SIZE * width;
	display->memory_height = DISPLAY_CELL_SIZE * height + 1;
	display->memory_stride = width;

	glBindVertexArray(display->memory_vao);
	glBindBuffer(GL_ARRAY_BUFFER, display->grid_vertex_buffer);
	glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (const void*)0);
	glBindBuffer(GL_ARRAY_BUFFER, display->memory_vertex_buffer);
	glVertexAttribPointer(1, 1, GL_UNSIGNED_BYTE, GL_FALSE, 1, (const void*)0);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glBindVertexArray(0);
}
bool ofxPostGlitch::addShader(const string &shaderPath)
{
	string fileName = ofSplitString(shaderPath, "\\").back();
	fileName = ofSplitString(fileName, "/").back();

	if (fileName == VERTEX_SHADER_NAME) return true;
    vector<string> shaderName = ofSplitString(fileName, ".");
    if (shaderName.size() != 2)
    {
        ofLogError(MODULE_NAME) << "inviled shader name: " << fileName;
        return false;
    }
    if (shaderName[1] == "frag" || shaderName[1] == "fr")
    {
        shaders.push_back(SHADER());
        shaders.back().flug = false;
        shaders.back().shaderName = shaderName[0];
        shaders.back().level = 1.0;
        if (!shaders.back().shader.load(dir.path() + "/" + VERTEX_SHADER_NAME, shaderPath))
        {
            ofLogError(MODULE_NAME) << "faild load shader: " << shaderPath;
            shaders.pop_back();
            return false;
        }
        ofLogVerbose(MODULE_NAME) << "load shader: " << shaderPath;
    }
    return true;
}
示例#3
0
GLhandleARB getShaders()
{
	static GLuint v, f, f2;
	GLhandleARB p;
	char *vs = NULL, *fs = NULL;

	v = glCreateShader(GL_VERTEX_SHADER);
	f = glCreateShader(GL_FRAGMENT_SHADER);

	//#define SHADER "pixeldirdifambspec"
	//#define SHADER "textureSimple"
	//#define SHADER "lightPointwise"
#define SHADER(path, post) path"mine"post

	vs = textFileRead(SHADER("shader/","_vertex.glsl"));
	fs = textFileRead(SHADER("shader/","_fragment.glsl"));

	const char * vv = vs;
	const char * ff = fs;

	glShaderSource(v, 1, &vv, NULL);
	glShaderSource(f, 1, &ff, NULL);

	free(vs); free(fs);

	glCompileShader(v);
	glCompileShader(f);

	printShaderInfoLog(v);
	printShaderInfoLog(f);

	p = glCreateProgram();
	glAttachShader(p, v);
	glAttachShader(p, f);

	glLinkProgram(p);
	printProgramInfoLog(p);

	time_loc = glGetUniformLocation(p, "time");
	shadow_map_loc = glGetUniformLocationARB(p, "ShadowMap");
	return p;
}
示例#4
0
SHADER ResourcePool::retrieveShader(string shaderName)
{
	map<string, SHADER>::iterator it = shaderContainer.find(shaderName);

	if (it != shaderContainer.end())
	{
		return it->second;
	}

	std::cout << "Unable to find shader! Check your naming!" << std::endl;

	return SHADER();
}
void display_gl_io_init(struct display_gl_s* display) {
	location_t			location[] = {
		{"in_Position", 0},
		{"in_Value", 1},
		{NULL, 0}
	};

	display->write_texture = display_gl_load_texture(TEXTURE("write.png"));
	display->read_texture = display_gl_load_texture(TEXTURE("read.png"));

	display_gl_load_shader(&display->io_shader, SHADER("io.vert"), SHADER("io.frag"), location);
	display->io_uniform_projection_matrix = glGetUniformLocation(display->io_shader.id, "uni_ProjectionMatrix");
	display->io_uniform_color = glGetUniformLocation(display->io_shader.id, "uni_Color");
	display->io_uniform_texture = glGetUniformLocation(display->io_shader.id, "uni_Texture");

	glUseProgram(display->io_shader.id);
	GLint		samplerId = 0;
	glUniform1iv(display->io_uniform_texture, 1, &samplerId);
	glUseProgram(0);

	display->io_read_buffer = (uint8*)malloc(display->memory_size * 4);
	display->io_write_buffer = (uint8*)malloc(display->memory_size * 4);
}