コード例 #1
0
void FBO::createRenderTarget(std::string textureName){
	chkGLErr();
	bind();
	auto texID = Texture::createTextureID(textureName);
	glBindTexture(GL_TEXTURE_2D, texID);
	chkGLErr();
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	chkGLErr();
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	chkGLErr();
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  _size.x, _size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
	chkGLErr();
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0+_renderTargets.size(), GL_TEXTURE_2D, texID, 0);
	chkGLErr();
	
	chkGLErr();
	_renderTargets.push_back(GL_COLOR_ATTACHMENT0+_renderTargets.size());
	_textures.push_back(texID);
	chkGLErr();

	unbind();
	LOG_INFO("Render target " << textureName << " created with size" << _size);
}
コード例 #2
0
ファイル: Light.cpp プロジェクト: r-englund/rGraphicsLibrary
void Light::set(){
	
	chkGLErr();
	int light = GL_LIGHT0+_id;
	glEnable(light);chkGLErr();

	glLightfv(light, GL_AMBIENT, glm::value_ptr(_ambientColor));chkGLErr();
	glLightfv(light, GL_DIFFUSE, glm::value_ptr(_diffuseColor));chkGLErr();
	glLightfv(light, GL_SPECULAR, glm::value_ptr(_specularColor));chkGLErr();
	
	
	chkGLErr();
/*
	glLightf(light, GL_CONSTANT_ATTENUATION,   _attenuation.x);
	glLightf(light, GL_LINEAR_ATTENUATION,     _attenuation.y);
	glLightf(light, GL_QUADRATIC_ATTENUATION,  _attenuation.z);*/

	glLightfv(light, GL_POSITION, glm::value_ptr(_position));
	
	chkGLErr();
	
	glLightf(light, GL_SPOT_CUTOFF, _spotCutOff);
	glLightf(light, GL_SPOT_EXPONENT, _spotExponent);
	glLightfv(light, GL_SPOT_DIRECTION,  glm::value_ptr(_spotDirection));
	
	chkGLErr();
}
コード例 #3
0
void resize(int width,int height){
	chkGLErr();
	glMatrixMode(GL_PROJECTION);
	chkGLErr();
	
	winSize.x = width;
	winSize.y = height;
	glLoadMatrixf(glm::value_ptr(glm::ortho(0.f,1.f,0.f,1.f)));
	chkGLErr();
	

	glMatrixMode(GL_MODELVIEW);
	glViewport(0,0,width,height);
	chkGLErr();
}
コード例 #4
0
int main( int argc, char* argv[] )
{
	if (glfwInit() != GL_TRUE){
		std::cout << "Could not init glfw"<< std::endl;
		return 2;
	}

	if (glfwOpenWindow(600, 600, 8, 8, 8, 8, 32, 0, GLFW_WINDOW) != GL_TRUE){
		std::cout << "Could not create window"<< std::endl;
		return 3;
	}
	glfwSetWindowTitle ("rGraphicsLibrary - Game of Life");

	if(glewInit() != GLEW_OK)
	{
		std::cerr << "Failed to init glew" << std::endl;
		exit(1);
	}
	chkGLErr();
	std::cout << "OpenGL Version: " << OpenGLInfo::getOpenGLVersion() << std::endl;
	std::cout << "Glew   Version: " << OpenGLInfo::getGlewVersion()   << std::endl;
	std::cout << "GLSL   Version: " << OpenGLInfo::getGLSLVersion()   << std::endl;
	std::cout << "OpenGL Vendor: "  << OpenGLInfo::getOpenGLVendor()   << std::endl;
	std::cout << "OpenGL Renderer: "<< OpenGLInfo::getOpenGLRenderer()   << std::endl;
	chkGLErr();

	init();

	glfwSetWindowSizeCallback(GLFWwindowsizefun(resize));

	while(true){
		if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
			break;
		evolve();
		draw();

		glfwSleep(0.5);
		
	}
	return 0;
}
コード例 #5
0
void FBO::init(std::string depthTexName){
	chkGLErr();
	if(_isInit) return;
	_isInit = true;
	

	_depthTex = Texture::createTextureID(depthTexName);
	glBindTexture(GL_TEXTURE_2D, _depthTex);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

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

	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, _size.x, _size.y, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
	
	glBindTexture(GL_TEXTURE_2D, 0);
	chkGLErr();


	glGenFramebuffersEXT(1, &_fbo);
	bind();
	
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT,  GL_TEXTURE_2D, _depthTex, 0);
	fboerror();

	
	unbind();
	
	chkGLErr();

	LOG_INFO("FBO initzilized with size " << _size << " and depth buffer " << depthTexName);

}
コード例 #6
0
void draw(){
	chkGLErr();
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glScalef(1.0f/winSize.x,1.0f/winSize.y,0);
	
	float dx = winSize.x / (float) dim.x;
	float dy = winSize.y / (float) dim.y;
	glBegin(GL_QUADS);
	glColor3f(1,1,0);
	for(int x = 0;x<dim.x;x++)for(int y = 0;y<dim.y;y++)if(grid[x][y]){
		glVertex2f(x*dx,y*dy);	
		glVertex2f(x*dx+dx,y*dy);	
		glVertex2f(x*dx+dx,y*dy+dy);	
		glVertex2f(x*dx,y*dy+dy);	
	}
	glEnd();



	glfwSwapBuffers();
	chkGLErr();
}
コード例 #7
0
void init(){
	chkGLErr();
	glClearColor(0,0,0,0);
	
	grid = new bool*[dim.x];
	tmpGrid = new bool*[dim.x];
	for(int i = 0;i<dim.x;i++){
		grid[i] = new bool[dim.y];
		tmpGrid[i] = new bool[dim.y];
		for(int j = 0;j<dim.y;j++){
			grid[i][j] = false; //rand() % 100 < 10;
			tmpGrid[i][j] = false;
		}
	}
	
	int o = 5;
	grid[4+o][1+o] = true;
	grid[5+o][1+o] = true;
	grid[8+o][1+o] = true;
	grid[9+o][1+o] = true;
	grid[10+o][1+o] = true;
	
	grid[1+o][2+o] = true;
	grid[2+o][2+o] = true;
	grid[3+o][2+o] = true;
	grid[5+o][2+o] = true;
	grid[7+o][2+o] = true;
	grid[9+o][2+o] = true;
	grid[10+o][2+o] = true;
	
	grid[1+o][3+o] = true;
	grid[2+o][3+o] = true;
	grid[3+o][3+o] = true;
	grid[4+o][3+o] = true;
	grid[5+o][3+o] = true;
	grid[8+o][3+o] = true;
	grid[9+o][3+o] = true;
	grid[10+o][3+o] = true;
	
	grid[1+o][4+o] = true;
	grid[3+o][4+o] = true;
	grid[5+o][4+o] = true;
	grid[7+o][4+o] = true;
	grid[9+o][4+o] = true;
	grid[11+o][4+o] = true;
	
	grid[2+o][5+o] = true;
	grid[4+o][5+o] = true;
	grid[6+o][5+o] = true;
	grid[8+o][5+o] = true;
	grid[9+o][5+o] = true;
	grid[10+o][5+o] = true;
	grid[11+o][5+o] = true;

	
	grid[5+o][6+o] = true;
	grid[6+o][6+o] = true;
	grid[7+o][6+o] = true;


	grid[1+o][7+o] = true;
	grid[2+o][7+o] = true;
	grid[3+o][7+o] = true;
	grid[4+o][7+o] = true;
	grid[6+o][7+o] = true;
	grid[8+o][7+o] = true;
	grid[10+o][7+o] = true;
	
	grid[1+o][8+o] = true;
	grid[3+o][8+o] = true;
	grid[5+o][8+o] = true;
	grid[7+o][8+o] = true;
	grid[9+o][8+o] = true;
	grid[11+o][8+o] = true;
	
	grid[2+o][9+o] = true;
	grid[3+o][9+o] = true;
	grid[4+o][9+o] = true;
	grid[7+o][9+o] = true;
	grid[8+o][9+o] = true;
	grid[9+o][9+o] = true;
	grid[10+o][9+o] = true;
	grid[11+o][9+o] = true;
	
	grid[2+o][10+o] = true;
	grid[3+o][10+o] = true;
	grid[5+o][10+o] = true;
	grid[7+o][10+o] = true;
	grid[9+o][10+o] = true;
	grid[10+o][10+o] = true;
	grid[11+o][10+o] = true;
	
	grid[2+o][11+o] = true;
	grid[3+o][11+o] = true;
	grid[4+o][11+o] = true;
	grid[7+o][11+o] = true;
	grid[8+o][11+o] = true;
	

	chkGLErr();
}