예제 #1
0
void Slideshow::paintGL ()
{
  int elapsed = timer.elapsed();
  
  logGLError("before paintGL");

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix ();

  glLoadIdentity ();
  double sz = std::min(width(), height());
  glScaled (currentZoom, currentZoom, 1.0);
  glTranslated (-panX + (width()-sz)/2.0, -panY + (height()-sz)/2.0, -10.0);
  glScaled (sz, sz, 1.0);

  glEnableClientState (GL_VERTEX_ARRAY);
  glEnableClientState (GL_TEXTURE_COORD_ARRAY);
  glVertexPointer (3, GL_FLOAT, 0, rect);

  drawImage(texs[0], inImage, fadeInOpacity(elapsed));
  drawImage(texs[1], outImage, fadeOutOpacity(elapsed));

  glPopMatrix ();

  logGLError("after paintGL");
  
  if (elapsed < fadeTime)
    update ();
  else if (slideshowRunning)
    slideTimer->start(slideTime);
  
  if (elapsed >= fadeTime + slideTime && slideshowRunning)
    nextImage ();
}
예제 #2
0
void Slideshow::loadTexture (QString filename)
{
  logGLError("before loadTexture");
  QImage t = convertToGLFormat( QPixmap (filename).toImage() );
  if (t.width() > 2048 || t.height() > 2048) {
    // better downscale, old graphics cards don't do big textures
    t = t.scaled (2048, 2048, Qt::KeepAspectRatio);
  }
  logGLError("in convertToGLFormat");
  inImage = t;
  setTexture (&t, 1);
  logGLError("in setTexture");
}
예제 #3
0
void Slideshow::setTexture (QImage ts[], uint length)
{
  glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP);
  logGLError("in glTexParameteri");
  for (uint i=0; i<length; i++) {
    QImage t = ts[i];
    int w = t.width ();
    int h = t.height ();
    glTexImage2D (GL_TEXTURE_RECTANGLE, i, 3 + (t.hasAlphaChannel() ? 1 : 0), w, h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, t.bits());
    logGLError("in glTexImage2D");
  }
}
예제 #4
0
void Slideshow::initializeGL ()
{

  logGLError("before initializeGL");

  glClearColor (0.0, 0.0, 0.0, 1.0);
  glDisable (GL_DEPTH_TEST);
  glEnable (GL_TEXTURE_RECTANGLE);
  glEnable (GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glGenTextures (3, texs);
  setDirectory(currentDir.absolutePath());

  logGLError("after initializeGL");
}
예제 #5
0
void initialize() {
   DEBUG_M("Initializing dglw...");
   logGLError();
   if(glGenVertexArrays == nullptr) {
      ERROR("Vertex Array Objects not supported...");
      return;
   }
   Cube::initialize();
   TextureQuad::initialize();
}
예제 #6
0
파일: glerror.c 프로젝트: drakmaniso/glam
void errorCallback(
    GLenum source,
    GLenum type,
    GLuint id,
    GLenum severity,
    GLsizei length,
    const GLchar *message,
    const void *userParam)
{
  logGLError(source, type, id, severity, length, (char *)message);
}
예제 #7
0
void RenderSystem::update(double time, SystemMessageSender* msgSender)
{
	std::vector<c_handle<NewRenderComponent>> renderComps = 
		GameObjectFactory::getComponentHandlesOfType<NewRenderComponent>();

	std::vector<c_handle<CameraComponent>> cameraHandles = GameObjectFactory::getComponentHandlesOfType<CameraComponent>();
	c_handle<CameraComponent> cameraHandle;
	if (cameraHandles.size() > 0) {
		cameraHandle = cameraHandles[0];
	}
	_ASSERT(cameraHandle);

	float shininess = 50;
	float attenuation = 0.00009f;
	glm::vec4 ambient(0.15f, 0.15f, 0.15f, 1.0f);
	glm::vec4 diffuse(0.9f, 0.9f, 0.9f, 1.0f);

	glm::mat4 projMat = cameraHandle->projectionMatrix;
	glm::mat4 viewMat = cameraHandle->getViewMatrix(cameraHandle);

	skyBox.draw(viewMat, projMat);
	glm::vec4 lightPosV = viewMat * glm::vec4(-60.0f, 8.0f, -20.0f, 1.0f);

	//shadowFBO.renderShadowPass(compHandles, lightPosV.xyz);

	//intt totalRenders = GameStateMachine::getCaptureFrames()? 2: 1;

	int totalRenders = 1;

	for (int count = 0; count < totalRenders; count++) {

	// TODO: set viewport on canvas
	if (count == 1) {
		glViewport(0,0, frameFBO.resWidth, frameFBO.resHeight);
		glBindFramebuffer(GL_FRAMEBUFFER, frameFBO.fbo);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		//skyBox.draw(viewMat, projMat);
	}
	else {
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glViewport(0, 0, GLsizei(cameraHandle->width), GLsizei(cameraHandle->height));
	}

	static int debug = 0;
	if (debug++ < 60) {
		logGLError("Draw:");
	}

	//glEnable (GL_BLEND);

	for (c_handle<NewRenderComponent> &renderH : renderComps)
	{
		c_handle<GameEntity> parentP = renderH->getParentEntity();
		if (renderH && renderH->getParentEntity()){
			c_handle<TransformComponent> transformHandle = 
				GameObjectFactory::getComponentBrother<TransformComponent>(renderH);
			c_handle<ShaderComponent> shaderH = 
				GameObjectFactory::getComponentBrother<ShaderComponent>(renderH);
			c_handle<NewTextureComponent> texHandle = 
				GameObjectFactory::getComponentBrother<NewTextureComponent>(renderH);
			
			if(transformHandle && shaderH)
			{
				TransformComponent& transform = transformHandle.get();

				std::vector<UniformBind> uniforms;
				uniforms.push_back(UniformsFuncs::createUniform<float>(
					UniformsFuncs::set1f, "shininess", shininess));
				uniforms.push_back(UniformsFuncs::createUniform<float, float, float, float>(
					UniformsFuncs::set4f, "specularColor", 1.0f, 1.0f, 1.0f, 1.0f));
				uniforms.push_back(UniformsFuncs::createUniform<int, const float*>(
					UniformsFuncs::set3fv, "lightpos", 1, &lightPosV[0])); 
				//TODO: check why not &lightPosV[0]

				uniforms.push_back(UniformsFuncs::createUniform<int, bool, const float*>(
					UniformsFuncs::setMat4fv, "viewMatrix", 1, false, &viewMat[0][0]));

				uniforms.push_back(UniformsFuncs::createUniform<int, bool, const float*>(
					UniformsFuncs::setMat4fv, "projectionMatrix", 1, false,
					&cameraHandle->projectionMatrix[0][0]));

				glm::vec3 offset=glm::vec3();
				glm::vec3 offsetRot=glm::vec3();
				float signo = 1.0f;

				c_handle<OffsetComponent> offsetH = 
					GameObjectFactory::getComponentBrother<OffsetComponent>(renderH);
				if(offsetH)
				{
					offset = offsetH->offsetMov;
					offsetRot = offsetH->offsetRot;
					glm::mat4 identity;
				}
					
				glm::vec3 orient = signo * (glm::eulerAngles(transform.orientation) 
					+ offsetRot.xyz);
				glm::quat quaternion = glm::quat(orient);

				glm::mat4 rotationTranslate = glm::translate(offset);

				glm::mat4 rotation = glm::mat4_cast(quaternion);
				glm::mat4 mat = glm::translate(transform.position) * rotation * rotationTranslate 
					* glm::scale(transform.scale);

				uniforms.push_back(UniformsFuncs::createUniform<int, bool, const float*>(
					UniformsFuncs::setMat4fv, "modelMatrix", 1, false, &transform.worldModelMat[0][0]));

				std::vector<Texture2D> texs;
				if (texHandle) {
					glm::vec4& Kd = texHandle->mKd;
					glm::vec4& Ka = texHandle->mKa;

					uniforms.push_back(UniformsFuncs::createUniform<float, float, float, float>(
						UniformsFuncs::set4f, "lightIntensity", diffuse.x * Kd.x, diffuse.y * Kd.y,
						diffuse.z * Kd.z, diffuse.w * Kd.w));
					uniforms.push_back(UniformsFuncs::createUniform<float, float, float, float>(
						UniformsFuncs::set4f, "ambientIntensity", ambient.x*Ka.x, ambient.y*Ka.y,
						ambient.z*Ka.z, ambient.w*Ka.w));

					uniforms.push_back(UniformsFuncs::createUniform<float>(UniformsFuncs::set1f,
						"lightAttenuation", attenuation * texHandle->mLightAttenuation));

					texs = std::vector<Texture2D>(texHandle->mTexs);
				}
				else {
					uniforms.push_back(UniformsFuncs::createUniform<int, const float*>(
						UniformsFuncs::set4fv, "lightIntensity", 1, &diffuse[0]));
					uniforms.push_back(UniformsFuncs::createUniform<int, const float*>(
						UniformsFuncs::set4fv, "ambientIntensity", 1, &ambient[0]));
					uniforms.push_back(UniformsFuncs::createUniform<float>(UniformsFuncs::set1f,
						"lightAttenuation", attenuation));
				}

				// agregar las uniforms de cada render component
				for (auto it = renderH->mProperties.begin(); it != renderH->mProperties.end(); ++it) {
					UniformBind uni = it->second->bind(it->first);
					uniforms.push_back(uni);
				}
					
				this->mCanvas.draw(shaderH->shaderProgramId, renderH->mPrimitive, 
					renderH->mData.mVAO, renderH->mData.mUsedIndices, (void*)renderH->mDrawOffset, 
					texs, uniforms);
			}
		}
	}

	//glDisable(GL_BLEND);

		if (count == 1) {
			frameFBO.saveFrame("frame");
		}

	}

	c_handle<TransformComponent> camPosH = 
		GameObjectFactory::getComponentBrother<TransformComponent>(cameraHandle);
	bool flag = true;

	
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
예제 #8
0
파일: Program.cpp 프로젝트: dcbishop/dglw
Program::Program() {
   program_id_ = glCreateProgram();
   logGLError();
}
예제 #9
0
파일: Program.cpp 프로젝트: dcbishop/dglw
void Program::detach(Shader& shader) {
   glAttachShader(program_id_, shader.getShaderId());
   logGLError();
}
예제 #10
0
파일: Program.cpp 프로젝트: dcbishop/dglw
void Program::attach(Shader& shader) {
   // TODO: Remove me? To force use of ShaderPtr
   glAttachShader(program_id_, shader.getShaderId());
   logGLError();
}
예제 #11
0
파일: Program.cpp 프로젝트: dcbishop/dglw
Program::~Program() {
   glDeleteProgram(program_id_);
   logGLError();
}