Пример #1
0
	STARTDECL(ph_render) ()
	{
		CheckPhysics();
		auto oldobject2view = object2view;
		auto oldcolor = curcolor;
		for (b2Body *body = world->GetBodyList(); body; body = body->GetNext())
		{
			auto pos = body->GetPosition();
			auto mat = translation(float3(pos.x, pos.y, 0)) * rotationZ(body->GetAngle());
			object2view = oldobject2view * mat;

			for (b2Fixture *fixture = body->GetFixtureList(); fixture; fixture = fixture->GetNext())
			{
				auto shapetype = fixture->GetType();
				auto r = (Renderable *)fixture->GetUserData();
				curcolor = r->color;
				r->Set();
				switch (shapetype)
				{
					case b2Shape::e_polygon:
					{
						auto polyshape = (b2PolygonShape *)fixture->GetShape();
						RenderArray(PRIM_FAN, polyshape->m_count, "pn", sizeof(b2Vec2), polyshape->m_vertices, NULL, 
							                                              sizeof(b2Vec2), polyshape->m_normals);
						break;
					}
					case b2Shape::e_circle:
					{
						// FIXME: instead maybe cache a circle verts somewhere.. though should maxverts be changable?
						const int maxverts = 20;
						struct PhVert { float2 pos; float2 norm; } phverts[maxverts];
						auto polyshape = (b2CircleShape *)fixture->GetShape();
						float step = PI * 2 / maxverts;
						for (int i = 0; i < maxverts; i++)
						{
							auto pos = float2(sinf(i * step + 1), cosf(i * step + 1));
							phverts[i].pos = pos * polyshape->m_radius + *(float2 *)&polyshape->m_p;
							phverts[i].norm = pos;
						}
						RenderArray(PRIM_FAN, maxverts, "pn", sizeof(PhVert), phverts, NULL);
						break;
					}
					case b2Shape::e_edge:
					case b2Shape::e_chain:
          case b2Shape::e_typeCount:
						assert(0);
						break;
				}
			}
		}
		object2view = oldobject2view;
		curcolor = oldcolor;
		return Value();
	}
Пример #2
0
void RenderCircle(Shader *sh, Primitive prim, int segments, float radius)
{
    assert(segments >= 3);

    auto &vbo = circlevbos[segments];

    if (!vbo)
    {
        auto vbuf = new float3[segments];

        float step = PI * 2 / segments;
        for (int i = 0; i < segments; i++)
        {
            // + 1 to reduce "aliasing" from exact 0 / 90 degrees points
            vbuf[i] = float3(sinf(i * step + 1),
                             cosf(i * step + 1), 0);
        }

        vbo = GenBO(GL_ARRAY_BUFFER, sizeof(float3), segments, vbuf);
        delete[] vbuf;
    }

    Transform2D(float4x4(float4(float2_1 * radius, 1)), [&]()
    {
        sh->Set();
        RenderArray(prim, segments, segments, "P", sizeof(float3), vbo);
    });
}
Пример #3
0
    STARTDECL(gl_polygon) (Value &vl)
    {
        TestGL();

        if (vl.vval->len < 3) g_vm->BuiltinError("polygon: must have at least 3 verts");

        auto vbuf = new BasicVert[vl.vval->len];
        for (int i = 0; i < vl.vval->len; i++) vbuf[i].pos = ValueTo<float3>(vl.vval->at(i));

        auto v1 = vbuf[1].pos - vbuf[0].pos;
        auto v2 = vbuf[2].pos - vbuf[0].pos;
        auto norm = normalize(cross(v2, v1));
        for (int i = 0; i < vl.vval->len; i++)
        {
            vbuf[i].norm = norm;
            vbuf[i].tc = vbuf[i].pos.xy();
            vbuf[i].col = byte4_255;
        }

        RenderArray(currentshader, polymode, vl.vval->len, "PNTC", sizeof(BasicVert), vbuf);

        delete[] vbuf;

        return vl;
    }
Пример #4
0
void RenderArraySlow(Primitive prim, int tcount, int vcount, const char *fmt,
                     int vertsize1, void *vbuf1, int *ibuf, int vertsize2, void *vbuf2)
{
    uint vbo = GenBO(GL_ARRAY_BUFFER, vertsize1, vcount, vbuf1);
    uint vbo2 = vbuf2 ? GenBO(GL_ARRAY_BUFFER, vertsize2, vcount, vbuf2) : 0;
    uint ibo = ibuf ? GenBO(GL_ELEMENT_ARRAY_BUFFER, sizeof(int), tcount, ibuf) : 0;

    RenderArray(prim, tcount, vcount, fmt, vertsize1, vbo, ibo, vertsize2, vbo2);

    if (ibuf) glDeleteBuffers(1, &ibo);
    if (vbuf2) glDeleteBuffers(1, &vbo2);
    glDeleteBuffers(1, &vbo);
}
Пример #5
0
    STARTDECL(ph_renderparticles) (Value &particlescale)
    {
        CheckPhysics();
        if (!particlesystem) return Value();

        //DebugLog(1, (string("rendering particles: ") + inttoa(particlesystem->GetParticleCount())).c_str());
        auto verts = (float2 *)particlesystem->GetPositionBuffer();
        auto colors = (byte4 *)particlesystem->GetColorBuffer();
        auto scale = fabs(object2view[0].x());
        SetPointSprite(scale * particlesystem->GetRadius() * particlescale.fval);
        particlematerial->Set();
        RenderArray(PRIM_POINT, particlesystem->GetParticleCount(), "pC", sizeof(float2), verts, NULL, sizeof(byte4), colors);
        return Value();
    }
Пример #6
0
    STARTDECL(gl_circle) (Value &radius, Value &segments)
    {
        TestGL();

        auto vbuf = new float3[segments.ival];

        float step = PI * 2 / segments.ival;
        for (int i = 0; i < segments.ival; i++)
            vbuf[i] = float3(sinf(i * step + 1) * radius.fval,
                           cosf(i * step + 1) * radius.fval, 0);        // + 1 to reduce "aliasing" from exact 0 / 90 degrees points

        RenderArray(currentshader, polymode, segments.ival, "P", sizeof(float3), vbuf);

        delete[] vbuf;

        return Value();
    }
Пример #7
0
void RenderOpenCircle(Shader *sh, int segments, float radius, float thickness)
{
    assert(segments >= 3);

    auto vbo_type = make_pair(segments, thickness);
    auto &vibo = opencirclevbos[vbo_type];

    auto nverts = segments * 2;
    auto nindices = segments * 6;

    if (!vibo.first)
    {
        auto vbuf = new float3[nverts];
        auto ibuf = new int[nindices];

        float step = PI * 2 / segments;
        float inner = 1 - thickness;
        for (int i = 0; i < segments; i++)
        {
            // + 1 to reduce "aliasing" from exact 0 / 90 degrees points
            float x = sinf(i * step + 1);
            float y = cosf(i * step + 1);
            vbuf[i * 2 + 0] = float3(x, y, 0);
            vbuf[i * 2 + 1] = float3(x * inner, y * inner, 0);
            ibuf[i * 6 + 0] = i * 2 + 0;
            ibuf[i * 6 + 1] = ((i + 1) * 2 + 0) % nverts;
            ibuf[i * 6 + 2] = i * 2 + 1;
            ibuf[i * 6 + 3] = i * 2 + 1;
            ibuf[i * 6 + 4] = ((i + 1) * 2 + 1) % nverts;
            ibuf[i * 6 + 5] = ((i + 1) * 2 + 0) % nverts;
        }

        vibo.first = GenBO(GL_ARRAY_BUFFER, sizeof(float3), nverts, vbuf);
        vibo.second = GenBO(GL_ELEMENT_ARRAY_BUFFER, sizeof(int), nindices, ibuf);
        delete[] vbuf;
        delete[] ibuf;
    }

    Transform2D(float4x4(float4(float2_1 * radius, 1)), [&]()
    {
        sh->Set();
        RenderArray(PRIM_TRIS, nindices, nverts, "P", sizeof(float3), vibo.first, vibo.second);
    });
}
Пример #8
0
void RenderUnitCube(Shader *sh)
{
    struct cvert { float3 pos; float3 normal; };

    if (!cube_vbo)
    {
        static int3 normals[] =
        {
            int3(1, 0, 0), int3(-1,  0,  0),
            int3(0, 1, 0), int3( 0, -1,  0),
            int3(0, 0, 1), int3( 0,  0, -1),
        };

        static const char *faces[6] = { "4576", "0231", "2673", "0154", "1375", "0462" };
        static int indices[6] = { 0, 1, 3, 1, 2, 3 };

        vector<cvert> verts;
        vector<int> triangles;

        for (int n = 0; n < 6; n++)
        {
            auto face = faces[n];
            for (int i = 0; i < 6; i++) triangles.push_back(indices[i] + (int)verts.size());
            for (int vn = 0; vn < 4; vn++)
            {
                cvert vert;
                for (int d = 0; d < 3; d++)
                {
                    vert.pos.set(d, float((face[vn] & (1 << (2 - d))) != 0));
                }
                vert.normal = float3(normals[n]);
                verts.push_back(vert);
            }
        }

        cube_vbo = GenBO(GL_ARRAY_BUFFER, sizeof(cvert), 24, verts.data());
        cube_ibo = GenBO(GL_ELEMENT_ARRAY_BUFFER, sizeof(int), 36, triangles.data());
    }

    sh->Set();
    RenderArray(PRIM_TRIS, 36, 24, "PN", sizeof(cvert), cube_vbo, cube_ibo);
}
Пример #9
0
    STARTDECL(gl_rect) (Value &vec)
    {
        TestGL();

        auto v = ValueTo<float3>(vec);

        static float tempquad_rect[20] =
        {
            0, 0, 0, 0, 0,
            0, 0, 0, 0, 1,
            0, 0, 0, 1, 1,
            0, 0, 0, 1, 0,
        };
        tempquad_rect[ 6] = tempquad_rect[11] = v.y();
        tempquad_rect[10] = tempquad_rect[15] = v.x();

        RenderArray(currentshader, polymode, 4, "PT", sizeof(float) * 5, tempquad_rect);

        return vec;
    }
Пример #10
0
void RenderUnitSquare(Shader *sh, Primitive prim, bool centered)
{
    int quadsize = sizeof(float) * 5;
    if (!quadvbo[centered])
    {
        static float vb_square[20] =
        {
            0, 0, 0, 0, 0,
            0, 1, 0, 0, 1,
            1, 1, 0, 1, 1,
            1, 0, 0, 1, 0,
        };
        static float vb_square_centered[20] =
        {
            -1, -1, 0, 0, 0,
            -1,  1, 0, 0, 1,
             1,  1, 0, 1, 1,
             1, -1, 0, 1, 0,
        };
        quadvbo[centered] = GenBO(GL_ARRAY_BUFFER, quadsize, 4, centered ? vb_square_centered : vb_square);
    }
    sh->Set();
    RenderArray(prim, 4, 4, "PT", quadsize, quadvbo[centered]);
}
Пример #11
0
void RenderLine(Shader *sh, Primitive prim, const float3 &v1, const float3 &v2, const float3 &side)
{
    float3 templine[4] = { v1 + side, v1 - side, v2 - side, v2 + side };
    RenderArray(sh, prim, 4, "P", sizeof(float3), templine);
}
void FirstLevelState::Render(void)
{
    map.Render();
    RenderArray();
    map.RenderMinimap();
}
Пример #13
0
void StageState::Render() {
	bg.Render(0, 0);
	bg.Render(bg.GetWidth(), 0);
	bg.Render(bg.GetWidth(), bg.GetHeight());
	bg.Render(0, bg.GetHeight());
	tileMap.Render(Camera::pos.GetXpoint(), Camera::pos.GetYpoint());

	moneyText.SetText(to_string(data->money));
	moneyText.SetPos(20, 20, false, false);
	moneyText.Render();

	SDL_Rect fillRect = { 20, 70, 100, 10 };
	if (data->fame <= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255 - data->fame, 0, data->fame, 255);
	}
	if (data->fame >= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255, 255, 255, 255);
	}
	SDL_RenderFillRect(Game::GetInstance().GetRenderer(), &fillRect);
	
	for(int i = 0; i < roomArray.size(); i++){
        roomArray[i]->Render(&tileMap);
    }
	switch (action)	{
	case NONE:
		RenderArray();
		occupancyMap.Render(&tileMap);
		break;
	case TILE_SELECT:
		selectionBox.Render(&tileMap);
		RenderArray();
		break;
	case GUI_ROOM:
		RenderArray();
		roomSheet.RenderRoomSheet();
		break;
	case CONSTRUCT_ROOM:
		selectionBox.Render(&tileMap);
		RenderArray();
		break;
	case DESTROY_ROOM:
		RenderArray();
		break;
	case AREA_SELECT:
		RenderArray();
		break;
	case GUI_A:
		RenderArray();
		gui.Render();
		break;
	case SUB_GUI_EDIT :
		RenderArray();
		subGuiEdit.Render();
		break;
	case EDIT_DOOR:
		RenderArray();
		break;
	case BUY:
		RenderArray();
		buySheet.RenderObjectSheet();
		break;
	case EDIT_OBJECT:{
			vector<Point> tiles = objectArray[selectedObject]->GetAccessPoints();
			for (int i = 0; i < tiles.size(); i++){
				Point center = tileMap.GetTileCenter(tiles[i]);
				center.x = center.x - tileMap.GetTileWidth()/2;
				center.y = center.y - tileMap.GetTileHeight()/2;

				if (obstacleMap[(tiles[i].y)*tileMap.GetWidth() + tiles[i].x] != -1){
					okTile.Render(center.x + Camera::pos.x, center.y+Camera::pos.y);
				}
				else{
					noTile.Render(center.x + Camera::pos.x, center.y + Camera::pos.y);
				}
			}

		}

		RenderArray();
		break;
	default:
		RenderArray();
		break;
	}
	if (sheet.GetRender()){
		sheet.SetHunger(to_string(objectArray[selectedCharacter]->GetHunger()));
		sheet.SetSatisfaction(to_string(int(objectArray[selectedCharacter]->satisfaction)));
		sheet.SetMoney(to_string(objectArray[selectedCharacter]->money));
		sheet.Render();
	}
	if (objSheet.GetRender()){
		objSheet.Open(objectArray[selectedCharacter]->GetTextAttributes());
		objSheet.Render();
	}

	//Dinheiro e fama
	
		
	moneyText.SetText(to_string(data->money));
	moneyText.SetPos(20, 20, false, false);
	moneyText.Render();

	costText.Render();

	if (data->fame <= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255 - data->fame, 0, data->fame, 255);
	}
	if (data->fame >= 255){
		SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 255, 255, 255, 255);
	}
	SDL_RenderFillRect(Game::GetInstance().GetRenderer(), &fillRect);
	int anchorx = data->fame * 100 / 255;
	SDL_SetRenderDrawColor(Game::GetInstance().GetRenderer(), 153, 153, 0, 255);
	fillRect = { 20 + anchorx, 68, 3, 14 };
	SDL_RenderFillRect(Game::GetInstance().GetRenderer(), &fillRect);
}