Пример #1
0
void endDraw(void)
{
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();

	render->disableTexCoordArray();
	render->disableColorArray();
	render->disableNormalArray();
	render->enableVertexArray();

	render->setVertexPointer(M_FLOAT, 3, g_vertices);
	render->drawArray(g_primitiveType, 0, g_verticesNumber);
}
Пример #2
0
void MGui2d::drawShadow(void)
{
	MRenderingContext * render = MGui::getInstance()->getRenderingContext();

	MVector2 g_vertices[8];
	MVector4 g_colors[8];

	render->disableTexture();
	render->enableBlending();
	render->setBlendingMode(M_BLENDING_ALPHA);

	MVector4 color0 = MVector4(0, 0, 0, 0);
	MVector4 color1 = MVector4(0, 0, 0, 0.05f);

	float size = 4;

	MVector2 dir[4];
	dir[0] = MVector2(size, size*0.4f);
	dir[1] = MVector2(size*0.4f, size);
	dir[2] = MVector2(size*0.4f, size*0.1f);
	dir[3] = MVector2(size*0.1f, size*0.4f);

	render->disableNormalArray();
	render->disableTexCoordArray();
	render->enableVertexArray();
	render->enableColorArray();

	render->setVertexPointer(M_FLOAT, 2, g_vertices);
	render->setColorPointer(M_FLOAT, 4, g_colors);

	for(int i=0; i<4; i++)
	{
		g_colors[0] = color1;
		g_vertices[0] = MVector2(0, m_scale.y) + MVector2(dir[i].x, 0);
		g_colors[1] = color0;
		g_vertices[1] = MVector2(0, m_scale.y) + MVector2(size, size) + dir[i];

		g_colors[2] = color1;
		g_vertices[2] = MVector2(m_scale.x, m_scale.y);
		g_colors[3] = color0;
		g_vertices[3] = MVector2(m_scale.x, m_scale.y) + MVector2(size, size) + dir[i];

		g_colors[4] = color1;
		g_vertices[4] = MVector2(m_scale.x, 0) + MVector2(0, dir[i].y);
		g_colors[5] = color0;
		g_vertices[5] = MVector2(m_scale.x, 0) + MVector2(size, size) + dir[i];

		render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 6);
	}
}
Пример #3
0
void MGui2d::drawQuad(void)
{
	MRenderingContext * render = MGui::getInstance()->getRenderingContext();

	MVector2 g_vertices[8];

	render->disableNormalArray();
	render->disableTexCoordArray();
	render->disableColorArray();
	render->enableVertexArray();

	g_vertices[0] = MVector2(m_position.x, m_position.y);
	g_vertices[1] = MVector2(m_position.x, m_position.y + m_scale.y);
	g_vertices[3] = MVector2(m_position.x + m_scale.x, m_position.y + m_scale.y);
	g_vertices[2] = MVector2(m_position.x + m_scale.x, m_position.y);

	render->setVertexPointer(M_FLOAT, 2, g_vertices);
	render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 4);
}
Пример #4
0
void MGuiTextureFont::drawSelection(const char * text, const MVector2 & position, float size, unsigned int startId, unsigned int endId)
{
	MRenderingContext * render = MGui::getInstance()->getRenderingContext();

	if(startId == endId)
		return;

	MVector2 g_vertices[4];

	render->disableNormalArray();
	render->disableColorArray();
	render->disableTexCoordArray();
	render->enableVertexArray();

	render->setVertexPointer(M_FLOAT, 2, g_vertices);

	unsigned int start;
	unsigned int end;

	if(endId > startId)
	{
		start = startId;
		end = endId;
	}
	else
	{
		start = endId;
		end = startId;
	}

	render->disableTexture();

	MVector2 startPosition = getCharacterPosition(text, position, size, start);
	float xc = startPosition.x;
	float yc = startPosition.y;

	float offset = (size - (size*getSpace()))*0.5f;

	// left quad
	g_vertices[0] = MVector2(xc+offset, yc);
	g_vertices[1] = MVector2(xc+offset, yc+size);

	unsigned int i;
	unsigned int textLength = strlen(text);
	for(i=start; i<end && i<textLength; i++)
	{
		if(text[i] == '\n')	// return
		{
			// right quad
			{
				g_vertices[3] = MVector2(xc+size*0.5f, yc+size);							
				g_vertices[2] = MVector2(xc+size*0.5f, yc);
				render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 4);
			}

			yc += size;
			xc = position.x;

			// left quad
			{
				g_vertices[0] = MVector2(xc+offset, yc);
				g_vertices[1] = MVector2(xc+offset, yc+size);
			}
		}
		else if(text[i] == '	') // tab
		{
			xc += size * getTabSpace();

			if(i+1 == end || i+1 == textLength)
			{
				// right quad
				g_vertices[3] = MVector2(xc+offset, yc+size);							
				g_vertices[2] = MVector2(xc+offset, yc);
				render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 4);
			}
		}
		else
		{
			xc += size * getSpace(); //move to next character

			if(i+1 == end || i+1 == textLength)
			{
				// right quad
				g_vertices[3] = MVector2(xc+offset, yc+size);							
				g_vertices[2] = MVector2(xc+offset, yc);
				render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 4);
			}
		}
	}
}
Пример #5
0
void MGuiEditText::draw(void)
{
	MRenderingContext * render = MGui::getInstance()->getRenderingContext();

	if(! isVisible())
		return;

	if(! isPressed())
		updateFromVariable();

	// draw selection
	if(isPressed())
	{
		render->disableTexture();
		render->setColor4(MVector4(1, 0.1f, 0.1f, 0.3f));
		getFont()->drawSelection(getText(), getPosition(), getTextSize(), m_startSelectionId, m_endSelectionId);
	}

	// set text color
	if(isPressed()){
		render->setColor4(getPressedColor());
	}
	else if(isHighLight()){
		render->setColor4(getHighLightColor());
	}
	else{
		render->setColor4(getNormalColor());
	}

	// draw text
	render->enableTexture();
	getFont()->draw(getText(), getPosition(), getTextSize());

	if(isPressed() && (m_startSelectionId == m_endSelectionId)) // cursor
	{
		render->disableTexture();

		render->setColor4(MVector4(1, 0, 0, 0.5f));

		// position
		MVector2 position = getFont()->getCharacterPosition(
			getText(),
			getPosition(),
			getTextSize(),
			getCharId()
		);

		// scale
		MVector2 scale = MVector2(getTextSize() * 0.1f, getTextSize());

		float offset = (getTextSize() - (getTextSize()*getFont()->getSpace()))*0.5f;
		float px = (float)((int)(position.x + offset));
		float py = (float)((int)position.y);

		// draw
		render->disableNormalArray();
		render->disableTexCoordArray();
		render->disableColorArray();
		render->enableVertexArray();

		MVector2 vertices[4] = {
			MVector2(px, py),
			MVector2(px, py + scale.y),
			MVector2(px + scale.x, py),
			MVector2(px + scale.x, py + scale.y)
		};

		render->setVertexPointer(M_FLOAT, 2, vertices);
		render->drawArray(M_PRIMITIVE_TRIANGLE_STRIP, 0, 4);
	}

	MGuiEvent guiEvent;
	guiEvent.type = MGUI_EVENT_DRAW;
	if(m_pointerEvent)
		m_pointerEvent(this, &guiEvent);
}
Пример #6
0
void MFixedRenderer::drawDisplay(MSubMesh * subMesh, MDisplay * display, MVector3 * vertices, MVector3 * normals, MColor * colors)
{
    M_PROFILE_SCOPE(MFixedRenderer::drawDisplay);
	MEngine * engine = MEngine::getInstance();
	MRenderingContext * render = engine->getRenderingContext();
	
	
	render->setColor4(MVector4(1, 1, 1, 1));
	

	// get material
	MMaterial * material = display->getMaterial();
	{
		float opacity = material->getOpacity();
		if(opacity <= 0.0f)
			return;
		
		// data
		M_TYPES indicesType = subMesh->getIndicesType();
		void * indices = subMesh->getIndices();
		MVector2 * texCoords = subMesh->getTexCoords();

		// begin / size
		unsigned int begin = display->getBegin();
		unsigned int size = display->getSize();
		
		// get properties
		M_PRIMITIVE_TYPES primitiveType = display->getPrimitiveType();
		M_BLENDING_MODES blendMode = material->getBlendMode();
		M_CULL_MODES cullMode = display->getCullMode();
		MVector3 * diffuse = material->getDiffuse();
		MVector3 * specular = material->getSpecular();
		MVector3 * emit = material->getEmit();
		float shininess = material->getShininess();
		
		// get current fog color
		MVector3 currentFogColor;
		render->getFogColor(&currentFogColor);
		
		// set cull mode
		if(cullMode == M_CULL_NONE){
			render->disableCullFace();
		}
		else{
			render->enableCullFace();
			render->setCullMode(cullMode);
		}
		
		// texture passes
		unsigned int texturesPassNumber = MIN(8, material->getTexturesPassNumber());
		
		// set blending mode
		render->setBlendingMode(blendMode);
		
		// alpha test
		if(blendMode != M_BLENDING_ALPHA && texturesPassNumber > 0)
		{
			MTexturePass * texturePass = material->getTexturePass(0);
			MTexture * texture = texturePass->getTexture();
			if(texture)
			{
				if(texture->getTextureRef()->getComponents() > 3)
					render->setAlphaTest(0.5f);
			}
		}
		
		// set fog color depending on blending
		switch(blendMode)
		{
			case M_BLENDING_ADD:
			case M_BLENDING_LIGHT:
				render->setFogColor(MVector3(0, 0, 0));
				break;
			case M_BLENDING_PRODUCT:
				render->setFogColor(MVector3(1, 1, 1));
				break;
		}
		
		// fixed pipeline
		{
			// no FX
			render->bindFX(0);
			
			// Vertex
			render->enableVertexArray();
			render->setVertexPointer(M_FLOAT, 3, vertices);
			
			// Normal
			if(normals)
			{
				render->enableNormalArray();
				render->setNormalPointer(M_FLOAT, normals);
			}
			
			// Color
			if(colors)
			{
				render->disableLighting();
				render->enableColorArray();
				render->setColorPointer(M_UBYTE, 4, colors);
			}
			
			// Material
			render->setMaterialDiffuse(MVector4(diffuse->x, diffuse->y, diffuse->z, opacity));
			render->setMaterialSpecular(MVector4(*specular));
			render->setMaterialAmbient(MVector4());
			render->setMaterialEmit(MVector4(*emit));
			render->setMaterialShininess(shininess);
			
			// switch to texture matrix mode
			if(texturesPassNumber > 0)
				render->setMatrixMode(M_MATRIX_TEXTURE);
			else
				render->disableTexture();
			
			// Textures
			int id = texturesPassNumber;
			for(unsigned int t=0; t<texturesPassNumber; t++)
			{
				MTexturePass * texturePass = material->getTexturePass(t);
				
				MTexture * texture = texturePass->getTexture();
				if((! texture) || (! texCoords))
				{
					render->bindTexture(0, t);
					render->disableTexture();
					render->disableTexCoordArray();
					continue;
				}
				
				// texCoords
				unsigned int offset = 0;
				if(subMesh->isMapChannelExist(texturePass->getMapChannel()))
					offset = subMesh->getMapChannelOffset(texturePass->getMapChannel());
				
				// texture id
				unsigned int textureId = 0;
				MTextureRef * texRef = texture->getTextureRef();
				if(texRef)
					textureId = texRef->getTextureId();
				
				// bind texture
				render->bindTexture(textureId, t);
				render->enableTexture();
				render->setTextureCombineMode(texturePass->getCombineMode());
				render->setTextureUWrapMode(texture->getUWrapMode());
				render->setTextureVWrapMode(texture->getVWrapMode());
				
				// texture matrix
				render->loadIdentity();
				render->translate(MVector2(0.5f, 0.5f));
				render->scale(*texture->getTexScale());
				render->rotate(MVector3(0, 0, -1), texture->getTexRotate());
				render->translate(MVector2(-0.5f, -0.5f));
				render->translate(*texture->getTexTranslate());
				
				// texture coords
				render->enableTexCoordArray();
				render->setTexCoordPointer(M_FLOAT, 2, texCoords + offset);
			}
			
			// switch back to modelview matrix mode
			if(texturesPassNumber > 0)
				render->setMatrixMode(M_MATRIX_MODELVIEW);
			
			// draw
			if(indices)
			{
				switch(indicesType)
				{
					case M_USHORT:
						render->drawElement(primitiveType, size, indicesType, (unsigned short*)indices + begin);
						break;
					case M_UINT:
						render->drawElement(primitiveType, size, indicesType, (unsigned int*)indices + begin);
						break;
				}
			}
			else{
				render->drawArray(primitiveType, begin, size);
			}
			
			
			// disable arrays
			render->disableVertexArray();
			if(normals)
				render->disableNormalArray();
			if(colors)
				render->disableColorArray();
			
			// restore textures
			for(int t=(int)(id-1); t>=0; t--)
			{
				render->bindTexture(0, t);
				render->disableTexture();
				render->disableTexCoordArray();
				render->setTextureCombineMode(M_TEX_COMBINE_MODULATE);
				
				render->setMatrixMode(M_MATRIX_TEXTURE);
				render->loadIdentity();
				render->setMatrixMode(M_MATRIX_MODELVIEW);
			}
		}

		// restore fog and alpha test
		render->setFogColor(currentFogColor);
		if(blendMode != M_BLENDING_ALPHA)
			render->setAlphaTest(0.0f);
		
		// restore lighting
		if(colors)
			render->enableLighting();
	}
}