Exemplo n.º 1
0
void GLSLProgram::create() {
	prog = glCreateProgram();
	LOG_GL_ERRORS();
	for (GLSLShaders::iterator it = shaders.begin(); it != shaders.end(); ++it) {
		glAttachShader(prog, (*it)->shader);
	}
	LOG_GL_ERRORS();
}
Exemplo n.º 2
0
Texture2D* Texture2D::load(Image* image) {
	if(image->getDepth() > 1) {
		LOG_ERROR << "can only handle 2D Images, but " << image->getName() << " has a depth of " << image->getDepth() << std::endl;
		return NULL;
	}

	GLuint textureId;
	glGenTextures(1, &textureId);
	Texture2D* tex = new Texture2D(image->getName(), glm::uvec2(image->getWidth(), image->getHeight()), textureId, image->getFormat());
	tex->bind();

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	// Set texture interpolation method to use linear interpolation (no MIPMAPS)
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTexImage2D(GL_TEXTURE_2D,
		0, //mip map level 0..top
		GL_RGBA, //internal format of the data in memory
		image->getWidth(),
		image->getHeight(),
		0,//border width in pixels (can either be 1 or 0)
		image->getFormat(),	// Image format (i.e. RGB, RGBA, BGR etc.)
		image->getType(),// Image data type
		image->getData());// The actual image data itself

	tex->unbind();

	LOG_DEBUG << "loaded texture: " << image->getName() << image->getDimensions() << std::endl;
	LOG_GL_ERRORS();
	return tex;
}
Exemplo n.º 3
0
Texture2D* Texture2D::createDepth(const glm::uvec2& dim, const GLint format) {
	LOG_DEBUG << "create depth texture: " << dim << std::endl;
	GLuint textureId;
	glGenTextures(1, &textureId);

	Texture2D* tex = new Texture2D("generated",dim, textureId, format);
	tex->bind();

	glTexImage2D(GL_TEXTURE_2D, 0, format, dim.x, dim.y, 0 /*no border*/, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
	glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);

	LOG_GL_ERRORS();
	tex->unbind();

	return tex;
}
void FrameBufferObject::beginCommon() {
	glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT);

	glBindTexture(GL_TEXTURE_2D, GL_NONE);
	glBindFramebuffer(GL_FRAMEBUFFER, fb);
	glViewport(0, 0, dim.x, dim.y);
	LOG_GL_ERRORS();
}
Exemplo n.º 5
0
GLSLAttrib& GLSLAttrib::operator=(const glm::bvec4 value) {
	if (id >= 0) {
		glUniform4i(id, value.x?1:0, value.y?1:0, value.z?1:0, value.w?1:0);
		LOG_GL_ERRORS();
	} else {
		LOG_WARN << "skip setting invalid parameter: " << name << std::endl;
	}
	return *this;
}
Exemplo n.º 6
0
GLSLAttrib& GLSLAttrib::operator=(const bool value) {
	if (id >= 0) {
		glUniform1i(id, value?1:0);
		LOG_GL_ERRORS();
	} else {
		LOG_WARN << "skip setting invalid parameter: " << name << std::endl;
	}
	return *this;
}
Exemplo n.º 7
0
GLSLAttrib& GLSLAttrib::operator=(Texture* value) {
	if (id >= 0 && value->isBound()) {
		glUniform1i(id, value->bindedTexture);
		LOG_GL_ERRORS();
	} else if(!value->isBound()){
		LOG_ERROR << "texture(" << value->textureId << ") is not bound" << std::endl;
	} else {
		LOG_WARN << "skip setting invalid parameter: " << name << std::endl;
	}
	return *this;
}
void FrameBufferObject::begin(unsigned int target) {
	beginCommon();

	if(target < 0 || target >= textures.size()) {
		glDrawBuffer(GL_NONE);
		glReadBuffer(GL_NONE);
	} else {
		glDrawBuffer(GL_COLOR_ATTACHMENT0+target);
		glReadBuffer(GL_COLOR_ATTACHMENT0+target);
	}
	LOG_GL_ERRORS();
}
void FrameBufferObject::beginAll() {
	beginCommon();

	GLenum* buffer = new GLenum[textures.size()];
	for(unsigned i = 0; i < textures.size(); ++i) {
		buffer[i] = GL_COLOR_ATTACHMENT0+i;
	}
	glDrawBuffers(textures.size(), buffer);

	delete[] buffer;
	LOG_GL_ERRORS();

}
Exemplo n.º 10
0
void display() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();

	glTranslatef(0,0,translateZ);

	glRotatef(rotationX, 0.0f, -1.0f, 0.0f);
	glRotatef(rotationY, -1.0f, 0.0f, 0.0f);
	
	LOG_GL_ERRORS();
	glutSwapBuffers();
}
Exemplo n.º 11
0
FrameBufferObject::FrameBufferObject(glm::uvec2 dim, const std::vector<Texture2D*>& textures, Texture2D* depthTexture) :
	dim(dim), textures(textures), depthTexture(depthTexture) {
	LOG_INFO << "create fbo: " << dim.x << " " << dim.y << std::endl;

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

	LOG_GL_ERRORS();

	LOG_DEBUG << "attach textures" << std::endl;
	// attach
	assert(textures.size() <= 15);
	for (unsigned i = 0; i < textures.size(); ++i) {
		Texture2D* tex = textures[i];
		assert (dim.x == tex->getWidth() && dim.y == tex->getHeight());
		LOG_DEBUG << "attach color texture " << i << std::endl;
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_TEXTURE_2D, tex->textureId, 0);
	}
	if(textures.size() <= 0) {
		// instruct openGL that we won't bind a color texture with the currently binded FBO
		glDrawBuffer(GL_NONE);
		glReadBuffer(GL_NONE);
	}

	if (depthTexture != NULL) {
		assert (dim.x == depthTexture->getWidth() && dim.y == depthTexture->getHeight());
		LOG_DEBUG << "attach depth texture" << std::endl;
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture->textureId, 0);
	}

	LOG_DEBUG << "check errors" << std::endl;
	checkError();
	LOG_DEBUG << "checked errors" << std::endl;

	glBindFramebuffer(GL_FRAMEBUFFER, GL_NONE);
	LOG_GL_ERRORS();
}
Exemplo n.º 12
0
Texture2D* Texture2D::createColor(const glm::uvec2& dim, const GLint format) {
	LOG_DEBUG << "create color texture: " << dim << std::endl;
	GLuint textureId;
	glGenTextures(1, &textureId);

	Texture2D* tex = new Texture2D("generated",dim, textureId, format);
	tex->bind();

	glTexImage2D(GL_TEXTURE_2D, 0, format, dim.x, dim.y, 0 /*no border*/, GL_RGB, GL_UNSIGNED_BYTE, NULL);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);


	LOG_GL_ERRORS();

	tex->unbind();
	return tex;
}