Пример #1
0
static inline void drawLight(vec2 * pos, float size){
	glPushMatrix();
	glTranslatef(pos->x,pos->y,0);
	backTransform();
	glTranslatef(0,0.2,0);
		Begin(GL_TRIANGLE_FAN);
			TexCoord2f (0.0f, 0.0f);
			Vertex2f(-size,-size);
			TexCoord2f (0.0f, 1.0f);
			Vertex2f(-size,size);
			TexCoord2f (1.0f, 1.0f);
			Vertex2f(size,size);
			TexCoord2f (1.0f, 0.0f);
			Vertex2f(size,-size);
		End();
	glPopMatrix();
}
Пример #2
0
void drawLightsMask(){
	Color4f(1,1,1,0.95);
	setTexture(lights);
//	glEnable(GL_TEXTURE_2D);
//	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA);
	Begin(GL_TRIANGLE_FAN);
		TexCoord2f (0.01f, 0.01f);
		Vertex2f(0,0);
		TexCoord2f (0.01f, 0.99f);
		Vertex2f(0,config.options.window.height);
		TexCoord2f (0.99f, 0.99f);
		Vertex2f(config.options.window.width,config.options.window.height);
		TexCoord2f (0.99f, 0.01f);
		Vertex2f(config.options.window.width,0);
	End();
//	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
}
Пример #3
0
unsigned int MDCSurface_read(Surface& surface, const byte* buffer)
{
  mdcSurface_t mdcSurface;
  {
    PointerInputStream inputStream(buffer);
    istream_read_mdcSurface(inputStream, mdcSurface);
  }

  {
    surface.vertices().reserve(mdcSurface.numVerts);

    PointerInputStream xyzStream(buffer + mdcSurface.ofsXyzNormals);
    PointerInputStream stStream(buffer + mdcSurface.ofsSt);
    // read verts into vertex array - xyz, st, normal
    for(std::size_t i = 0; i < mdcSurface.numVerts; i++)
	  {
      mdcXyzNormal_t mdcXyzNormal;
      istream_read_mdcXyzNormal(xyzStream, mdcXyzNormal);
      mdcSt_t mdcSt;
      istream_read_mdcSt(stStream, mdcSt);

      surface.vertices().push_back(
        ArbitraryMeshVertex(
          Vertex3f( mdcXyzNormal.xyz[0] * MDC_XYZ_SCALE, mdcXyzNormal.xyz[1] * MDC_XYZ_SCALE, mdcXyzNormal.xyz[2] * MDC_XYZ_SCALE),
          DecodeNormal(reinterpret_cast<byte*>(&mdcXyzNormal.normal)),
          TexCoord2f(mdcSt.st[0], mdcSt.st[1])
        )
      );
    }
  }

  {
 	  surface.indices().reserve(mdcSurface.numTriangles * 3);

    PointerInputStream triangleStream(buffer + mdcSurface.ofsTriangles);

    for(std::size_t i = 0; i < mdcSurface.numTriangles; i++)
    {
      mdcTriangle_t triangle;
      istream_read_mdcTriangle(triangleStream, triangle);
      surface.indices().insert(triangle.indexes[0]);
      surface.indices().insert(triangle.indexes[1]);
      surface.indices().insert(triangle.indexes[2]);
    }
  }

  {
    mdcShader_t shader;
    PointerInputStream inputStream(buffer + mdcSurface.ofsShaders);
    istream_read_mdcShader(inputStream, shader);
    surface.setShader(shader.name);
  }
	
	surface.updateAABB();

  return mdcSurface.ofsEnd;
}
Пример #4
0
static inline void vertex (fpoint tl, fpoint br, float x, float y,
                           fsize tex_tl, fsize tex_br, fsize tex_uv)
{
    float tx = (x - tl.x) / tex_uv.width;
    tx *= tex_br.width - tex_tl.width;

    float ty = (y - tl.y) / tex_uv.height;
    ty *= tex_br.height - tex_tl.height;

    Color4u(gl_color_current());
    TexCoord2f(tx, ty);
    Vertex2f(x, y);
}
Пример #5
0
inline ArbitraryMeshVertex MDLVertex_construct( const mdlHeader_t& header, const mdlXyzNormal_t& xyz, const mdlSt_t& st, bool facesfront ){
	return ArbitraryMeshVertex(
			   Vertex3f(
				   xyz.v[0] * header.scale[0] + header.scale_origin[0],
				   xyz.v[1] * header.scale[1] + header.scale_origin[1],
				   xyz.v[2] * header.scale[2] + header.scale_origin[2]
				   ),
			   Normal3f(
				   g_mdl_normals[xyz.lightnormalindex][0],
				   g_mdl_normals[xyz.lightnormalindex][1],
				   g_mdl_normals[xyz.lightnormalindex][2]
				   ),
			   TexCoord2f(
				   ( (float)st.s / header.skinwidth ) + ( ( st.onseam == MDL_ONSEAM && !facesfront ) ? 0.5f : 0.0f ),
				   (float)st.t / header.skinheight
				   )
			   );
}
Пример #6
0
ArbitraryMeshVertex MD2Vertex_construct( const md2Header_t* pHeader, const md2Frame_t* pFrame, const md2XyzNormal_t* xyz, const md2St_t* st ){
	return ArbitraryMeshVertex(
			   Vertex3f(
				   xyz->v[0] * pFrame->scale[0] + pFrame->translate[0],
				   xyz->v[1] * pFrame->scale[1] + pFrame->translate[1],
				   xyz->v[2] * pFrame->scale[2] + pFrame->translate[2]
				   ),
			   Normal3f(
				   g_mdl_normals[xyz->lightnormalindex][0],
				   g_mdl_normals[xyz->lightnormalindex][1],
				   g_mdl_normals[xyz->lightnormalindex][2]
				   ),
			   TexCoord2f(
				   (float)st->s / pHeader->skinwidth,
				   (float)st->t / pHeader->skinheight
				   )
			   );
}
Пример #7
0
void MD5Surface::updateToSkeleton(const MD5Skeleton& skeleton)
{
	// Ensure we have all vertices allocated
	if (_vertices.size() != _mesh->vertices.size())
	{
		_vertices.resize(_mesh->vertices.size());
	}

	// Deform vertices to fit the skeleton
	for (std::size_t j = 0; j < _mesh->vertices.size(); ++j)
	{
		MD5Vert& vert = _mesh->vertices[j];

		Vector3 skinned(0, 0, 0);

		for (std::size_t k = 0; k != vert.weight_count; ++k)
		{
			MD5Weight& weight = _mesh->weights[vert.weight_index + k];
			const IMD5Anim::Key& key = skeleton.getKey(weight.joint);
			//const Joint& joint = skeleton.getJoint(weight.joint);

			Vector3 rotatedPoint = key.orientation.transformPoint(weight.v);
			skinned += (rotatedPoint + key.origin) * weight.t;
		}

		_vertices[j].vertex = skinned;
		_vertices[j].texcoord = TexCoord2f(vert.u, vert.v);
		_vertices[j].normal = Normal3f(0,0,0);
	}
    
	// Ensure the index array is ok
	if (_indices.empty())
	{
		buildIndexArray();
	}

	buildVertexNormals();

	updateGeometry();
}
Пример #8
0
void MD5Surface::updateToDefaultPose(const MD5Joints& joints)
{
	if (_vertices.size() != _mesh->vertices.size())
	{
		_vertices.resize(_mesh->vertices.size());
	}

	for (std::size_t j = 0; j < _mesh->vertices.size(); ++j)
	{
		MD5Vert& vert = _mesh->vertices[j];

		Vector3 skinned(0, 0, 0);

		for (std::size_t k = 0; k != vert.weight_count; ++k)
		{
			MD5Weight& weight = _mesh->weights[vert.weight_index + k];
			const MD5Joint& joint = joints[weight.joint];

			Vector3 rotatedPoint = joint.rotation.transformPoint(weight.v);
			skinned += (rotatedPoint + joint.position) * weight.t;
		}

		_vertices[j].vertex = skinned;
		_vertices[j].texcoord = TexCoord2f(vert.u, vert.v);
		_vertices[j].normal = Normal3f(0,0,0);
	}

	// Ensure the index array is ok
	if (_indices.empty())
	{
		buildIndexArray();
	}

	buildVertexNormals();

	updateGeometry();
}
Пример #9
0
	// Constructor. Copy the provided picoSurface_t structure into this object
	RenderablePicoSurface::RenderablePicoSurface (picoSurface_t* surf) :
		_originalShaderName(""), _mappedShaderName("")
	{
		// Get the shader from the picomodel struct.
		picoShader_t* shader = PicoGetSurfaceShader(surf);
		if (shader != 0) {
			_originalShaderName = PicoGetShaderName(shader);
		}

		// Capture the shader
		_shader = GlobalShaderCache().capture(_originalShaderName);
		if (_shader)
			_mappedShaderName = _originalShaderName; // no skin at this time

		// Get the number of vertices and indices, and reserve capacity in our vectors in advance
		// by populating them with empty structs.
		const int nVerts = PicoGetSurfaceNumVertexes(surf);
		_nIndices = PicoGetSurfaceNumIndexes(surf);
		_vertices.resize(nVerts);
		_indices.resize(_nIndices);

		// Stream in the vertex data from the raw struct, expanding the local AABB to include
		// each vertex.
		for (int vNum = 0; vNum < nVerts; ++vNum) {
			Vertex3f vertex(PicoGetSurfaceXYZ(surf, vNum));
			_localAABB.includePoint(vertex);
			_vertices[vNum].vertex = vertex;
			_vertices[vNum].normal = Normal3f(PicoGetSurfaceNormal(surf, vNum));
			_vertices[vNum].texcoord = TexCoord2f(PicoGetSurfaceST(surf, 0, vNum));
		}

		// Stream in the index data
		picoIndex_t* ind = PicoGetSurfaceIndexes(surf, 0);
		for (unsigned int i = 0; i < _nIndices; i++)
			_indices[i] = ind[i];
	}
// Constructor. Copy the provided picoSurface_t structure into this object
RenderablePicoSurface::RenderablePicoSurface(picoSurface_t* surf,
											 const std::string& fExt)
: _shaderName(""),
  _dlRegular(0),
  _dlProgramVcol(0),
  _dlProgramNoVCol(0)
{
	// Get the shader from the picomodel struct. If this is a LWO model, use
	// the material name to select the shader, while for an ASE model the
	// bitmap path should be used.
	picoShader_t* shader = PicoGetSurfaceShader(surf);
	std::string rawName = "";

	if (shader != 0)
	{
		if (fExt == "lwo")
		{
			_shaderName = PicoGetShaderName(shader);
		}
		else if (fExt == "ase")
		{
			rawName = PicoGetShaderName(shader);
			std::string rawMapName = PicoGetShaderMapName(shader);
			_shaderName = cleanupShaderName(rawMapName);
		}
	}

	// If shader not found, fallback to alternative if available
	// _shaderName is empty if the ase material has no BITMAP
	// materialIsValid is false if _shaderName is not an existing shader
	if ((_shaderName.empty() || !GlobalMaterialManager().materialExists(_shaderName)) &&
		!rawName.empty())
	{
		_shaderName = cleanupShaderName(rawName);
	}

	// Capturing the shader happens later on when we have a RenderSystem reference

    // Get the number of vertices and indices, and reserve capacity in our
    // vectors in advance by populating them with empty structs.
    int nVerts = PicoGetSurfaceNumVertexes(surf);
    _nIndices = PicoGetSurfaceNumIndexes(surf);
    _vertices.resize(nVerts);
    _indices.resize(_nIndices);

    // Stream in the vertex data from the raw struct, expanding the local AABB
    // to include each vertex.
    for (int vNum = 0; vNum < nVerts; ++vNum) {

    	// Get the vertex position and colour
		Vertex3f vertex(PicoGetSurfaceXYZ(surf, vNum));

		// Expand the AABB to include this new vertex
    	_localAABB.includePoint(vertex);

    	_vertices[vNum].vertex = vertex;
    	_vertices[vNum].normal = Normal3f(PicoGetSurfaceNormal(surf, vNum));
    	_vertices[vNum].texcoord = TexCoord2f(PicoGetSurfaceST(surf, 0, vNum));
    	_vertices[vNum].colour =
    		getColourVector(PicoGetSurfaceColor(surf, 0, vNum));
    }

    // Stream in the index data
    picoIndex_t* ind = PicoGetSurfaceIndexes(surf, 0);
    for (unsigned int i = 0; i < _nIndices; i++)
    	_indices[i] = ind[i];

	// Calculate the tangent and bitangent vectors
	calculateTangents();

	// Construct the DLs
	createDisplayLists();
}
Пример #11
0
void fhImmediateMode::TexCoord2fv(const float* v)
{
  TexCoord2f(v[0], v[1]);
}
Пример #12
0
void Tri_DrawScaledSprite( HSPRITE hSprite, int frame, int r, int g, int b, int a, const RenderMode renderMode, const float flScale, ITriCoordFallback& callback, const wrect_t* pSpriteRect )
{
	if( hSprite == INVALID_HSPRITE )
	{
		gEngfuncs.Con_DPrintf( "Tri_DrawScaledSprite: hSprite is invalid!\n" );
		return;
	}

	const int iOrigWidth = gEngfuncs.pfnSPR_Width( hSprite, frame );
	const int iOrigHeight = gEngfuncs.pfnSPR_Height( hSprite, frame );

	wrect_t subRect;

	if( pSpriteRect )
	{
		subRect = *pSpriteRect;
	}
	else
	{
		subRect.left = subRect.top = 0;
		subRect.right = iOrigWidth;
		subRect.bottom = iOrigHeight;
	}

	int x, y;

	//Fallback on Software; no scaling or render mode support. - Solokiller
	if( !IEngineStudio.IsHardware() )
	{
		//Always scale 1. - Solokiller
		callback.Calculate( hSprite, frame, subRect, 1.0f, x, y );

		gEngfuncs.pfnSPR_Set( hSprite, r, g, b );

		gEngfuncs.pfnSPR_DrawHoles( frame, x, y, pSpriteRect );

		return;
	}

	wrect_t rect;

	//Trim a pixel border around it, since it blends. - Solokiller
	rect.left = subRect.left * flScale + ( flScale - 1 );
	rect.top = subRect.top * flScale + ( flScale - 1 );
	rect.right = subRect.right * flScale - ( flScale - 1 );
	rect.bottom = subRect.bottom * flScale - ( flScale - 1 );

	const int iWidth = iOrigWidth * flScale;
	const int iHeight = iOrigHeight * flScale;

	callback.Calculate( hSprite, frame, rect, flScale, x, y );

	model_t* pCrosshair = const_cast<model_t*>( gEngfuncs.GetSpritePointer( hSprite ) );

	auto TriAPI = gEngfuncs.pTriAPI;

	TriAPI->SpriteTexture( pCrosshair, frame );

	TriAPI->Color4fRendermode( r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f, renderMode );
	TriAPI->RenderMode( renderMode );

	float flLeft = 0;
	float flTop = 0;
	float flRight = 1.0;
	float flBottom = 1.0f;

	int iImgWidth = iWidth;
	int iImgHeight = iHeight;

	AdjustSubRect( iWidth, iHeight, &flLeft, &flRight, &flTop, &flBottom, &iImgWidth, &iImgHeight, &rect );

	TriAPI->Begin( TriangleMode::TRI_QUADS );

	TriAPI->TexCoord2f( flLeft, flTop );
	TriAPI->Vertex3f( x, y, 0 );

	TriAPI->TexCoord2f( flRight, flTop );
	TriAPI->Vertex3f( x + iImgWidth, y, 0 );

	TriAPI->TexCoord2f( flRight, flBottom );
	TriAPI->Vertex3f( x + iImgWidth, y + iImgHeight, 0 );

	TriAPI->TexCoord2f( flLeft, flBottom );
	TriAPI->Vertex3f( x, y + iImgHeight, 0 );

	TriAPI->End();
}