Esempio n. 1
0
	// XXX Need a way to deal with blits with Camera/Lighting.
	void DisplayDeviceOpenGL::doBlitTexture(const TexturePtr& tex, int dstx, int dsty, int dstw, int dsth, float rotation, int srcx, int srcy, int srcw, int srch)
	{
		ASSERT_LOG(false, "DisplayDevice::doBlitTexture deprecated");
		ASSERT_LOG(!tex, "Texture passed in was not of expected type.");

		const float tx1 = float(srcx) / tex->width();
		const float ty1 = float(srcy) / tex->height();
		const float tx2 = srcw == 0 ? 1.0f : float(srcx + srcw) / tex->width();
		const float ty2 = srch == 0 ? 1.0f : float(srcy + srch) / tex->height();
		const float uv_coords[] = {
			tx1, ty1,
			tx2, ty1,
			tx1, ty2,
			tx2, ty2,
		};

		const float vx1 = float(dstx);
		const float vy1 = float(dsty);
		const float vx2 = float(dstx + dstw);
		const float vy2 = float(dsty + dsth);
		const float vtx_coords[] = {
			vx1, vy1,
			vx2, vy1,
			vx1, vy2,
			vx2, vy2,
		};

		// Apply blend mode from texture if there is any.
		BlendEquationScopeOGL be_scope(*tex);
		BlendModeScopeOGL bm_scope(*tex);

		glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3((vx1+vx2)/2.0f,(vy1+vy2)/2.0f,0.0f)) * glm::rotate(glm::mat4(1.0f), rotation, glm::vec3(0.0f,0.0f,1.0f)) * glm::translate(glm::mat4(1.0f), glm::vec3(-(vx1+vy1)/2.0f,-(vy1+vy1)/2.0f,0.0f));
		glm::mat4 mvp = glm::ortho(0.0f, 800.0f, 600.0f, 0.0f) * model;
		auto shader = OpenGL::ShaderProgram::defaultSystemShader();
		shader->makeActive();
		getDefaultShader()->setUniformsForTexture(tex);

		shader->setUniformValue(shader->getMvpUniform(), glm::value_ptr(mvp));
		shader->setUniformValue(shader->getColorUniform(), glm::value_ptr(glm::vec4(1.0f,1.0f,1.0f,1.0f)));
		// XXX the following line are only temporary, obviously.
		//shader->setUniformValue(shader->getUniform("discard"), 0);
		glEnableVertexAttribArray(shader->getVertexAttribute());
		glVertexAttribPointer(shader->getVertexAttribute(), 2, GL_FLOAT, GL_FALSE, 0, vtx_coords);
		glEnableVertexAttribArray(shader->getTexcoordAttribute());
		glVertexAttribPointer(shader->getTexcoordAttribute(), 2, GL_FLOAT, GL_FALSE, 0, uv_coords);

		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		glDisableVertexAttribArray(shader->getTexcoordAttribute());
		glDisableVertexAttribArray(shader->getVertexAttribute());
	}
Esempio n. 2
0
/** Method to scale the positions in the mesh. Normals will be kept as is. This is a potentially slow operation, use with care.
 * It will also create a temporary float[] which will be garbage collected.
 * 
 * @param scaleX scale on x
 * @param scaleY scale on y
 * @param scaleZ scale on z */
void Mesh::scale (float scaleX, float scaleY, float scaleZ) 
{
	//TODO:
	VertexAttribute posAttr(-1, 0, "");
	getVertexAttribute(VertexAttributes::Position, posAttr);
	int offset = posAttr.offset / 4;
	int numComponents = posAttr.numComponents;
	int numVertices = getNumVertices();
	int vertexSize = getVertexSize() / 4;
    
	float* vertices = new float[numVertices * vertexSize];
	memcpy(vertices, m_vertices->getBuffer(), sizeof(float) * numVertices * vertexSize);
    
	int idx = offset;
	switch (numComponents) 
	{
        case 1:
            for (int i = 0; i < numVertices; i++) 
            {
                vertices[idx] *= scaleX;
                idx += vertexSize;
            }
            break;
        case 2:
            for (int i = 0; i < numVertices; i++) 
            {
                vertices[idx] *= scaleX;
                vertices[idx + 1] *= scaleY;
                idx += vertexSize;
            }
            break;
        case 3:
            for (int i = 0; i < numVertices; i++) 
            {
                vertices[idx] *= scaleX;
                vertices[idx + 1] *= scaleY;
                vertices[idx + 2] *= scaleZ;
                idx += vertexSize;
            }
            break;
	}
	setVertices(vertices, numVertices * vertexSize);
	delete [] vertices;
}
Esempio n. 3
0
void Mesh::calculateBoundingBox(BoundingBox& bbox) 
{
    int numVertices = getNumVertices();
    if (numVertices == 0) 
        throw GdxRuntimeException("No vertices defined");
    
    float* verts = m_vertices->getBuffer();
    bbox.inf();
    VertexAttribute posAttrib;
    getVertexAttribute(VertexAttributes::Position, posAttrib);
    int offset = posAttrib.offset / 4;
    int vertexSize = m_vertices->getAttributes().vertexSize() / 4;
    int idx = offset;
    
    switch (posAttrib.numComponents) {
        case 1:
            for (int i = 0; i < numVertices; i++) 
            {
                bbox.ext(verts[idx], 0, 0);
                idx += vertexSize;
            }
            break;
        case 2:
            for (int i = 0; i < numVertices; i++) 
            {
                bbox.ext(verts[idx], verts[idx + 1], 0);
                idx += vertexSize;
            }
            break;
        case 3:
            for (int i = 0; i < numVertices; i++) 
            {
                bbox.ext(verts[idx], verts[idx + 1], verts[idx + 2]);
                idx += vertexSize;
            }
            break;
    }
}