Ejemplo n.º 1
0
void Context::Draw()
{
	Graphics::Renderer *r = GetRenderer();

	// Ticket for the viewport mostly
	Graphics::Renderer::StateTicket ticket(r);
	r->SetViewport(0, 0, m_width, m_height);

	// reset renderer for each layer
	for (std::vector<Layer*>::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
		r->SetOrthographicProjection(0, m_width, m_height, 0, -1, 1);
		r->SetTransform(matrix4x4f::Identity());
		r->SetClearColor(Color4f::BLACK);

		DrawWidget(*i);

		r->SetScissor(false);
	}

	if (m_mousePointer && m_mousePointerEnabled) {
		r->SetOrthographicProjection(0, m_width, m_height, 0, -1, 1);
		r->SetTransform(matrix4x4f::Identity());
		r->SetClearColor(Color4f::BLACK);
		DrawWidget(m_mousePointer);
		r->SetScissor(false);
	}
}
Ejemplo n.º 2
0
void Label3D::Render(const matrix4x4f &trans, const RenderData *rd)
{
	//needs alpha test
	Graphics::Renderer *r = GetRenderer();
	r->SetTransform(trans);
	r->DrawTriangles(m_geometry.Get(), m_material.Get());
}
Ejemplo n.º 3
0
void Billboard::Render(const matrix4x4f &trans, const RenderData *rd)
{
	Graphics::Renderer *r = GetRenderer();

	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0, 6);

	const matrix3x3f rot = trans.GetOrient().Transpose();

	//some hand-tweaked scaling, to make the lights seem larger from distance
	const float size = m_size * Graphics::GetFovFactor() * Clamp(trans.GetTranslate().Length() / 500.f, 0.25f, 15.f);

	const vector3f rotv1 = rot * vector3f(size/2.f, -size/2.f, 0.0f);
	const vector3f rotv2 = rot * vector3f(size/2.f, size/2.f, 0.0f);

	va.Add(m_offset-rotv1, vector2f(0.f, 0.f)); //top left
	va.Add(m_offset-rotv2, vector2f(0.f, 1.f)); //bottom left
	va.Add(m_offset+rotv2, vector2f(1.f, 0.f)); //top right

	va.Add(m_offset+rotv2, vector2f(1.f, 0.f)); //top right
	va.Add(m_offset-rotv2, vector2f(0.f, 1.f)); //bottom left
	va.Add(m_offset+rotv1, vector2f(1.f, 1.f)); //bottom right

	r->SetTransform(trans);
	r->DrawTriangles(&va, m_renderState, m_material.Get());
}
Ejemplo n.º 4
0
void Face::Draw()
{
	const Point &offset = GetActiveOffset();
	const Point &area = GetActiveArea();

	const float x = offset.x;
	const float y = offset.y;
	const float sx = area.x;
	const float sy = area.y;

	const vector2f texSize = m_texture->GetDescriptor().texSize;

	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);
	va.Add(vector3f(x,    y,    0.0f), vector2f(0.0f,      0.0f));
	va.Add(vector3f(x,    y+sy, 0.0f), vector2f(0.0f,      texSize.y));
	va.Add(vector3f(x+sx, y,    0.0f), vector2f(texSize.x, 0.0f));
	va.Add(vector3f(x+sx, y+sy, 0.0f), vector2f(texSize.x, texSize.y));

	Graphics::Renderer *r = GetContext()->GetRenderer();
	s_material->texture0 = m_texture.get();
	auto state = GetContext()->GetSkin().GetAlphaBlendState();
	r->DrawTriangles(&va, state, s_material.Get(), Graphics::TRIANGLE_STRIP);

	Single::Draw();
}
Ejemplo n.º 5
0
void VScrollPortal::Draw()
{
	PROFILE_SCOPED()
	SetScissor(true);

	float size[2];
	GetSize(size);

	m_scrollY = vscrollAdjust.GetValue();

	float toScroll = m_childSizeY - size[1];
	if (toScroll < 0) toScroll = 0;

	float scale[2];
	Screen::GetCoords2Pixels(scale);

	Graphics::Renderer *r = Gui::Screen::GetRenderer();
	Graphics::Renderer::MatrixTicket ticket(r, Graphics::MatrixMode::MODELVIEW);

	// scroll to whole pixel locations whatever the resolution
	r->Translate(0, floor((-m_scrollY*toScroll)/scale[1])*scale[1], 0);
	Container::Draw();

	SetScissor(false);
}
Ejemplo n.º 6
0
void Screen::LeaveOrtho()
{
	PROFILE_SCOPED()

	Graphics::Renderer *r = GetRenderer();

	r->SetProjection(projMatrix);
	r->SetTransform(modelMatrix);
}
Ejemplo n.º 7
0
void Image::Draw()
{
    float allocSize[2];
    GetSize(allocSize);

    Graphics::Renderer *r = Gui::Screen::GetRenderer();
    r->SetBlendMode(Graphics::BLEND_ALPHA);
    m_quad->Draw(r, 0, vector2f(allocSize[0],allocSize[1]), m_color);
}
Ejemplo n.º 8
0
void StaticGeometry::Render(const std::vector<matrix4x4f> &trans, const RenderData *rd)
{
	PROFILE_SCOPED()
	SDL_assert(m_renderState);
	Graphics::Renderer *r = GetRenderer();

	const size_t numTrans = trans.size();
	if (!m_instBuffer.Valid() || (numTrans > m_instBuffer->GetSize()))
	{
		// create the InstanceBuffer with the maximum number of transformations we might use within it.
		m_instBuffer.Reset( r->CreateInstanceBuffer(numTrans, Graphics::BUFFER_USAGE_DYNAMIC) );
	}

	// Update the InstanceBuffer data
	for(Uint32 i=0; i<numTrans; i++) {
		Graphics::InstanceBuffer* ib = m_instBuffer.Get();
		matrix4x4f *pBuffer = ib->Map(Graphics::BUFFER_MAP_WRITE);
		// Copy the transforms into the buffer
		for(auto mt : trans) {
			(*pBuffer) = mt;
			++pBuffer;
		}
		ib->Unmap();
		ib->SetInstanceCount(numTrans);
	}
	
	// we'll set the transformation within the vertex shader so identity the global one
	r->SetTransform(matrix4x4f::Identity());

	// process each mesh
	for (auto& it : m_meshes) {
		// Due to the shader needing to change we have to get the material and force it to the instanced variant
		Graphics::MaterialDescriptor mdesc = it.material->GetDescriptor();
		mdesc.instanced = true;
		// create the "new" material with the instanced description
		RefCountedPtr<Graphics::Material> mat(r->CreateMaterial(mdesc));
		// copy over all of the other details
		mat->texture0 = it.material->texture0;
		mat->texture1 = it.material->texture1;
		mat->texture2 = it.material->texture2;
		mat->texture3 = it.material->texture3;
		mat->texture4 = it.material->texture4;
		mat->texture5 = it.material->texture5;
		mat->texture6 = it.material->texture5;
		mat->heatGradient = it.material->heatGradient;
		mat->diffuse = it.material->diffuse;
		mat->specular = it.material->specular;
		mat->emissive = it.material->emissive;
		mat->shininess = it.material->shininess;
		mat->specialParameter0 = it.material->specialParameter0;
		// finally render using the instance material
		r->DrawBufferIndexedInstanced(it.vertexBuffer.Get(), it.indexBuffer.Get(), m_renderState, mat.Get(), m_instBuffer.Get());
	}
}
Ejemplo n.º 9
0
void StaticGeometry::Render(const matrix4x4f &trans, const RenderData *rd)
{
	PROFILE_SCOPED()
	SDL_assert(m_renderState);
	Graphics::Renderer *r = GetRenderer();
	r->SetTransform(trans);
	for (auto& it : m_meshes)
		r->DrawBufferIndexed(it.vertexBuffer.Get(), it.indexBuffer.Get(), m_renderState, it.material.Get());

	//DrawBoundingBox(m_boundingBox);
}
Ejemplo n.º 10
0
void ModelSpinner::Draw()
{
	Graphics::Renderer *r = GetContext()->GetRenderer();

	Graphics::Renderer::StateTicket ticket(r);

	const float fov = 45.f;
	r->SetPerspectiveProjection(fov, 1.f, 1.f, 10000.f);
	r->SetTransform(matrix4x4f::Identity());

	r->SetDepthWrite(true);
	r->SetDepthTest(true);
	r->ClearDepthBuffer();

	r->SetLights(1, &m_light);

	Point pos(GetAbsolutePosition() + GetActiveOffset());
	Point size(GetActiveArea());

	r->SetViewport(pos.x, GetContext()->GetSize().y - pos.y - size.y, size.x, size.y);

	matrix4x4f rot = matrix4x4f::RotateXMatrix(m_rotX);
	rot.RotateY(m_rotY);
	const float dist = m_model->GetDrawClipRadius() / sinf(DEG2RAD(fov*0.5f));
	rot[14] = -dist;
	m_model->Render(rot);
}
Ejemplo n.º 11
0
    /// Renders the title screen.
    /// @param[in,out]  renderer - The renderer to use for rendering.
    void TitleScreen::Render(GRAPHICS::Renderer& renderer) const
    {
        // DRAW THE SUB-HEADING FOR THE GAME'S TITLE.
        // It is centered within the top third of the screen.
        MATH::FloatRectangle screen_rectangle = renderer.Screen.GetBoundingRectangle<float>();
        float screen_left_x_position = screen_rectangle.GetLeftXPosition();
        float screen_top_y_position = screen_rectangle.GetTopYPosition();
        float screen_width_in_pixels = screen_rectangle.GetWidth();
        float screen_height_in_pixels = screen_rectangle.GetHeight();
        float one_third_of_screen_height_in_pixels = screen_height_in_pixels / 3.0f;
        MATH::FloatRectangle sub_heading_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            screen_top_y_position,
            screen_width_in_pixels,
            one_third_of_screen_height_in_pixels);
        const float BIBLE_GAMES_HEADING_TEXT_SCALE = 1.5f;
        renderer.RenderCenteredText(
            "BIBLE GAMES",
            sub_heading_screen_rectangle,
            GRAPHICS::Color::WHITE,
            BIBLE_GAMES_HEADING_TEXT_SCALE);

        // DRAW THE MAIN GAME'S TITLE.
        // It is centered within the middle third of the screen.
        MATH::FloatRectangle main_title_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            one_third_of_screen_height_in_pixels,
            screen_width_in_pixels,
            one_third_of_screen_height_in_pixels);
        const float TITLE_TEXT_SCALE = 3.0f;
        renderer.RenderCenteredText(
            "NOAH's ARK",
            main_title_screen_rectangle,
            GRAPHICS::Color::YELLOW,
            TITLE_TEXT_SCALE);

        // DRAW THE 'PRESS START' TEXT.
        // It is centered within the bottom third of the screen.
        float two_thirds_screen_height_in_pixels = 2 * one_third_of_screen_height_in_pixels;
        MATH::FloatRectangle press_enter_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            two_thirds_screen_height_in_pixels,
            screen_width_in_pixels,
            one_third_of_screen_height_in_pixels);
        renderer.RenderCenteredText(
            "PRESS ENTER",
            press_enter_screen_rectangle,
            GRAPHICS::Color::RED);
    }
Ejemplo n.º 12
0
void Context::Draw()
{
	Graphics::Renderer *r = GetRenderer();

	// reset renderer for each layer
	for (std::vector<Layer*>::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
		r->SetOrthographicProjection(0, m_width, m_height, 0, -1, 1);
		r->SetTransform(matrix4x4f::Identity());
		r->SetClearColor(Color::BLACK);

		(*i)->Draw();

		r->SetScissor(false);
	}
}
Ejemplo n.º 13
0
    /// Renders the inventory GUI Bible page to the provided screen.
    /// @param[in,out]  renderer - The renderer to use for rendering.
    void InventoryBiblePage::Render(GRAPHICS::Renderer& renderer) const
    {
        // RENDER A RECTANGLE FOR THE PAGE'S BACKGROUND.
        // It is offset from the top of the screen by the amount of the
        // GUI stuff that should always be displayed above it.  Otherwise,
        // it should cover the remainder of the screen.
        const float TOP_SCREEN_OFFSET_IN_PIXELS = static_cast<float>(2 * GRAPHICS::GUI::Glyph::HEIGHT_IN_PIXELS);
        const float SCREEN_LEFT_POSITION_IN_PIXELS = 0.0f;
        const float BACKGROUND_HEIGHT_IN_PIXELS = renderer.Screen.HeightInPixels<float>() - TOP_SCREEN_OFFSET_IN_PIXELS;
        MATH::FloatRectangle background_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            SCREEN_LEFT_POSITION_IN_PIXELS,
            TOP_SCREEN_OFFSET_IN_PIXELS,
            renderer.Screen.WidthInPixels<float>(),
            BACKGROUND_HEIGHT_IN_PIXELS);

        renderer.RenderScreenRectangle(
            background_rectangle,
            BACKGROUND_COLOR);

        // RENDER THE BOX FOR THE MAIN BIBLE VERSE DISPLAY.
        const BIBLE::BibleVerse* const selected_bible_verse = BibleVerseListBox.GetSelectedVerse();

        // The exact positioning/size of this box is tentative.
        const float BIBLE_VERSE_TEXT_BOX_SINGLE_SIDE_PADDING_IN_PIXELS = 4.0f;
        float bible_verse_text_box_left_screen_position_in_pixels = background_rectangle.GetLeftXPosition() + BIBLE_VERSE_TEXT_BOX_SINGLE_SIDE_PADDING_IN_PIXELS;
        float bible_verse_text_box_top_screen_position_in_pixels = background_rectangle.GetTopYPosition() + BIBLE_VERSE_TEXT_BOX_SINGLE_SIDE_PADDING_IN_PIXELS;
        float bible_verse_text_box_width_in_pixels = background_rectangle.GetWidth() / 2.0f;
        const float BIBLE_VERSE_TEXT_BOX_BOTH_SIDES_PADDING_IN_PIXELS = 2.0f * BIBLE_VERSE_TEXT_BOX_SINGLE_SIDE_PADDING_IN_PIXELS;
        float bible_verse_text_box_height_in_pixels = background_rectangle.GetHeight() - BIBLE_VERSE_TEXT_BOX_BOTH_SIDES_PADDING_IN_PIXELS;
        MATH::FloatRectangle bible_verse_text_box_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            bible_verse_text_box_left_screen_position_in_pixels,
            bible_verse_text_box_top_screen_position_in_pixels,
            bible_verse_text_box_width_in_pixels,
            bible_verse_text_box_height_in_pixels);

        BibleVerseTextBox.Render(
            selected_bible_verse,
            bible_verse_text_box_rectangle,
            renderer);

        // RENDER THE BOX FOR THE LIST OF ALL BIBLE VERSES.
        // The exact positioning/size of this box is tentative.
        float bible_verse_list_box_left_screen_position_in_pixels =
            (bible_verse_text_box_rectangle.GetRightXPosition() + BIBLE_VERSE_TEXT_BOX_SINGLE_SIDE_PADDING_IN_PIXELS);
        float bible_verse_list_box_top_screen_position_in_pixels = bible_verse_text_box_rectangle.GetTopYPosition();
        // Take up the remaining width (minus padding on the right).
        float bible_verse_list_box_width_in_pixels =
            background_rectangle.GetWidth() - bible_verse_list_box_left_screen_position_in_pixels - BIBLE_VERSE_TEXT_BOX_SINGLE_SIDE_PADDING_IN_PIXELS;
        float bible_verse_list_box_height_in_pixels = bible_verse_text_box_rectangle.GetHeight();
        MATH::FloatRectangle bible_verse_list_box_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            bible_verse_list_box_left_screen_position_in_pixels,
            bible_verse_list_box_top_screen_position_in_pixels,
            bible_verse_list_box_width_in_pixels,
            bible_verse_list_box_height_in_pixels);

        BibleVerseListBox.Render(
            bible_verse_list_box_rectangle,
            renderer);
    }
Ejemplo n.º 14
0
void Billboard::Render(const matrix4x4f &trans, const RenderData *rd)
{
	PROFILE_SCOPED()
	Graphics::Renderer *r = GetRenderer();

	const matrix3x3f rot = trans.GetOrient().Transpose();

	//some hand-tweaked scaling, to make the lights seem larger from distance
	const float size = m_size * Graphics::GetFovFactor() * Clamp(trans.GetTranslate().Length() / 500.f, 0.25f, 15.f);

	const vector3f rotv1 = rot * vector3f(size*0.5f, -size*0.5f, 0.0f);
	const vector3f rotv2 = rot * vector3f(size*0.5f, size*0.5f, 0.0f);

	if( !m_vbuffer.Valid() )
	{
		//create buffer and upload data
		Graphics::VertexBufferDesc vbd;
		vbd.attrib[0].semantic = Graphics::ATTRIB_POSITION;
		vbd.attrib[0].format   = Graphics::ATTRIB_FORMAT_FLOAT3;
		vbd.attrib[1].semantic = Graphics::ATTRIB_UV0;
		vbd.attrib[1].format   = Graphics::ATTRIB_FORMAT_FLOAT2;
		vbd.numVertices = 6;
		vbd.usage = Graphics::BUFFER_USAGE_DYNAMIC;	// we could be updating this per-frame
		m_vbuffer.Reset( r->CreateVertexBuffer(vbd) );
	}

#pragma pack(push, 4)
	struct PosUVVert {
		vector3f pos;
		vector2f uv;
	};
#pragma pack(pop)
	PosUVVert* vtxPtr = m_vbuffer->Map<PosUVVert>(Graphics::BUFFER_MAP_WRITE);
	vtxPtr[0].pos = (m_offset - rotv1); vtxPtr[0].uv = vector2f(0.f, 0.f); //top left
	vtxPtr[1].pos = (m_offset - rotv2); vtxPtr[1].uv = vector2f(0.f, 1.f); //bottom left
	vtxPtr[2].pos = (m_offset + rotv2); vtxPtr[2].uv = vector2f(1.f, 0.f); //top right
	vtxPtr[3].pos = (m_offset + rotv2); vtxPtr[3].uv = vector2f(1.f, 0.f); //top right
	vtxPtr[4].pos = (m_offset - rotv2); vtxPtr[4].uv = vector2f(0.f, 1.f); //bottom left
	vtxPtr[5].pos = (m_offset + rotv1); vtxPtr[5].uv = vector2f(1.f, 1.f); //bottom right
	m_vbuffer->Unmap();

	r->SetTransform(trans);
	r->DrawBuffer(m_vbuffer.Get(), m_renderState, m_material.Get());

	r->GetStats().AddToStatCount(Graphics::Stats::STAT_BILLBOARD, 1);
}
Ejemplo n.º 15
0
void ShipSpinner::Draw()
{

	Graphics::Renderer *r = GetContext()->GetRenderer();

	Graphics::Renderer::StateTicket ticket(r);

	r->SetPerspectiveProjection(45.f, 1.f, 1.f, 10000.f);
	r->SetTransform(matrix4x4f::Identity());

	r->SetDepthTest(true);
	r->ClearDepthBuffer();

	r->SetLights(1, &m_light);

	Point pos(GetAbsolutePosition() + GetActiveOffset());
	Point size(GetActiveArea());

	r->SetViewport(pos.x, GetContext()->GetSize().y - pos.y - size.y, size.x, size.y);

	matrix4x4f rot = matrix4x4f::RotateXMatrix(m_rotX);
	rot.RotateY(m_rotY);
	rot[14] = -1.5f * m_model->GetDrawClipRadius();
	m_model->Render(r, rot, &m_params);
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{
	FileSystem::Init();

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		Output("sdl init failed: %s\n", SDL_GetError());
		exit(-1);
	}

	Graphics::Settings videoSettings;
	videoSettings.width = WIDTH;
	videoSettings.height = HEIGHT;
	videoSettings.fullscreen = false;
	videoSettings.hidden = false;
	videoSettings.requestedSamples = 0;
	videoSettings.vsync = false;
	videoSettings.useTextureCompression = false;
	videoSettings.enableDebugMessages = false;
	videoSettings.iconFile = OS::GetIconFilename();
	videoSettings.title = "textstress";

	Graphics::Renderer *r = Graphics::Init(videoSettings);

	r->SetOrthographicProjection(0, WIDTH, HEIGHT, 0, -1, 1);
	r->SetTransform(matrix4x4f::Identity());
	r->SetClearColor(Color::BLACK);
	r->SetBlendMode(Graphics::BLEND_ALPHA);
	r->SetDepthTest(false);

	const Text::FontDescriptor fontDesc(Text::FontDescriptor::Load(FileSystem::gameDataFiles, "fonts/UIFont.ini", "en"));
	Text::TextureFont *font = new Text::TextureFont(fontDesc, r);

	std::string str;
	for (int i = 33; i < 127; i++)
		str.push_back(i);

	while (1) {
		bool done = false;

		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
				done = true;
		}
		if (done)
			break;

		font->RenderString(str.c_str(), rand()%(WIDTH*2)-WIDTH, rand()%HEIGHT, Color::WHITE);
		r->SwapBuffers();
	}

	delete font;
	delete r;

	SDL_Quit();

	exit(0);
}
Ejemplo n.º 17
0
/// Renders a tab that is part of the inventory GUI.
/// @param[in]  tab_text - The text to display on the tab.
/// @param[in]  left_top_screen_position_in_pixels - The left-top screen position of the tab.
/// @param[in]  background_color - The background color of the tab.
/// @param[in,out]  renderer - The renderer to use for rendering.
void InventoryGui::RenderTab(
    const std::string& tab_text,
    const MATH::Vector2f& left_top_screen_position_in_pixels,
    const GRAPHICS::Color& background_color,
    GRAPHICS::Renderer& renderer) const
{
    // RENDER A BACKGROUND RECTANGLE FOR THE TAB.
    unsigned int tab_text_width_in_pixels = GRAPHICS::GUI::Glyph::WIDTH_IN_PIXELS * tab_text.length();
    MATH::FloatRectangle tab_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            left_top_screen_position_in_pixels.X,
            left_top_screen_position_in_pixels.Y,
            static_cast<float>(tab_text_width_in_pixels),
            static_cast<float>(GRAPHICS::GUI::Glyph::HEIGHT_IN_PIXELS));

    renderer.RenderScreenRectangle(
        tab_rectangle,
        background_color);

    // RENDER THE TEXT FOR THE TAB.
    renderer.RenderText(tab_text, left_top_screen_position_in_pixels, GRAPHICS::Color::BLACK);
}
Ejemplo n.º 18
0
void Icon::Draw()
{
	const Point &offset = GetActiveOffset();
	const Point &area = GetActiveArea();

	const float x = offset.x;
	const float y = offset.y;
	const float sx = area.x;
	const float sy = area.y;

	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);
	va.Add(vector3f(x,    y,    0.0f), vector2f(s_texScale.x*(m_texPos.x),    s_texScale.y*(m_texPos.y)));
	va.Add(vector3f(x,    y+sy, 0.0f), vector2f(s_texScale.x*(m_texPos.x),    s_texScale.y*(m_texPos.y+48)));
	va.Add(vector3f(x+sx, y,    0.0f), vector2f(s_texScale.x*(m_texPos.x+48), s_texScale.y*(m_texPos.y)));
	va.Add(vector3f(x+sx, y+sy, 0.0f), vector2f(s_texScale.x*(m_texPos.x+48), s_texScale.y*(m_texPos.y+48)));

	Graphics::Renderer *r = GetContext()->GetRenderer();
	r->SetBlendMode(Graphics::BLEND_ALPHA);
	s_material->diffuse = m_color;
	r->DrawTriangles(&va, s_material.Get(), Graphics::TRIANGLE_STRIP);
}
Ejemplo n.º 19
0
void Gradient::Draw()
{
	const Point &offset = GetActiveOffset();
	const Point &area = GetActiveArea();

	const float x = offset.x;
	const float y = offset.y;
	const float sx = area.x;
	const float sy = area.y;

	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE);
	va.Add(vector3f(x,    y,    0.0f), m_beginColor);
	va.Add(vector3f(x,    y+sy, 0.0f), m_direction == HORIZONTAL ? m_beginColor : m_endColor);
	va.Add(vector3f(x+sx, y,    0.0f), m_direction == HORIZONTAL ? m_endColor : m_beginColor);
	va.Add(vector3f(x+sx, y+sy, 0.0f), m_endColor);

	Graphics::Renderer *r = GetContext()->GetRenderer();
	r->SetBlendMode(Graphics::BLEND_ALPHA);
	r->DrawTriangles(&va, m_material.Get(), Graphics::TRIANGLE_STRIP);

	Container::Draw();
}
Ejemplo n.º 20
0
void Image::Draw()
{
	const Point &offset = GetActiveOffset();
	const Point &area = GetActiveArea();

	const float x = offset.x;
	const float y = offset.y;
	const float sx = area.x;
	const float sy = area.y;

	const vector2f texSize = m_texture->GetDescriptor().texSize;

	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);
	va.Add(vector3f(x,    y,    0.0f), vector2f(0.0f,      0.0f));
	va.Add(vector3f(x,    y+sy, 0.0f), vector2f(0.0f,      texSize.y));
	va.Add(vector3f(x+sx, y,    0.0f), vector2f(texSize.x, 0.0f));
	va.Add(vector3f(x+sx, y+sy, 0.0f), vector2f(texSize.x, texSize.y));

	Graphics::Renderer *r = GetContext()->GetRenderer();
	r->SetBlendMode(Graphics::BLEND_ALPHA);
	r->DrawTriangles(&va, m_material.Get(), Graphics::TRIANGLE_STRIP);
}
Ejemplo n.º 21
0
void Thruster::Render(const matrix4x4f &trans, const RenderData *rd)
{
	float power = 0.f;
	power = -dir.Dot(vector3f(rd->linthrust));

	if (!linearOnly) {
		// pitch X
		// yaw   Y
		// roll  Z
		//model center is at 0,0,0, no need for invSubModelMat stuff
		const vector3f at = vector3f(rd->angthrust);
		const vector3f angdir = pos.Cross(dir);

		const float xp = angdir.x * at.x;
		const float yp = angdir.y * at.y;
		const float zp = angdir.z * at.z;

		if (xp+yp+zp > 0) {
			if (xp > yp && xp > zp && fabs(at.x) > power) power = fabs(at.x);
			else if (yp > xp && yp > zp && fabs(at.y) > power) power = fabs(at.y);
			else if (zp > xp && zp > yp && fabs(at.z) > power) power = fabs(at.z);
		}
	}
	if (power < 0.001f) return;

	Graphics::Renderer *r = GetRenderer();
	r->SetTransform(trans);

	r->SetBlendMode(Graphics::BLEND_ALPHA_ONE);
	r->SetDepthWrite(false);

	m_tMat->diffuse = m_glowMat->diffuse = baseColor * power;

	//directional fade
	vector3f cdir = vector3f(trans * -dir).Normalized();
	vector3f vdir = vector3f(trans[2], trans[6], -trans[10]).Normalized();
	// XXX check this for transition to new colors.
	m_glowMat->diffuse.a = Easing::Circ::EaseIn(Clamp(vdir.Dot(cdir), 0.f, 1.f), 0.f, 1.f, 1.f) * 255;
	m_tMat->diffuse.a = 255 - m_glowMat->diffuse.a;

	r->DrawTriangles(m_tVerts.get(), m_tMat.Get());
	r->DrawTriangles(m_glowVerts.get(), m_glowMat.Get());

	r->SetBlendMode(Graphics::BLEND_SOLID);
	r->SetDepthWrite(true);
}
Ejemplo n.º 22
0
void Context::Draw()
{
	Graphics::Renderer *r = GetRenderer();

	r->SetOrthographicProjection(0, m_width, m_height, 0, -1, 1);
	r->SetTransform(matrix4x4f::Identity());
	r->SetClearColor(Color::BLACK);
	r->SetBlendMode(Graphics::BLEND_ALPHA);
	r->SetDepthTest(false);

	Single::Draw();
	m_float->Draw();

	r->SetScissor(false);
}
Ejemplo n.º 23
0
void Screen::EnterOrtho()
{
	PROFILE_SCOPED()

	Graphics::Renderer *r = GetRenderer();

	modelMatrix = r->GetCurrentModelView();
	projMatrix = r->GetCurrentProjection();

	r->GetCurrentViewport(&viewport[0]);
	r->SetOrthographicProjection(0, width, height, 0, -1, 1);
	r->SetTransform(matrix4x4f::Identity());
}
Ejemplo n.º 24
0
/// Renders the page of the inventory for the food tab.
/// This page allows browsing food in the inventory.
/// @param[in,out]  renderer - The renderer to use for rendering.
void InventoryGui::RenderFoodPage(GRAPHICS::Renderer& renderer) const
{
    // RENDER A RECTANGLE FOR THE PAGE'S BACKGROUND.
    // It is offset from the top of the screen by the amount of the
    // GUI stuff that should always be displayed above it.  Otherwise,
    // it should cover the remainder of the screen.
    const float TOP_SCREEN_OFFSET_IN_PIXELS = static_cast<float>(2 * GRAPHICS::GUI::Glyph::HEIGHT_IN_PIXELS);
    const float SCREEN_LEFT_POSITION_IN_PIXELS = 0.0f;
    const float BACKGROUND_HEIGHT_IN_PIXELS = renderer.Screen.HeightInPixels<float>() - TOP_SCREEN_OFFSET_IN_PIXELS;
    MATH::FloatRectangle background_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
                SCREEN_LEFT_POSITION_IN_PIXELS,
                TOP_SCREEN_OFFSET_IN_PIXELS,
                renderer.Screen.WidthInPixels<float>(),
                BACKGROUND_HEIGHT_IN_PIXELS);

    renderer.RenderScreenRectangle(
        background_rectangle,
        FOOD_TAB_COLOR);
}
Ejemplo n.º 25
0
void Thruster::Render(const matrix4x4f &trans, const RenderData *rd)
{
	float power = 0.f;
	power = -dir.Dot(vector3f(rd->linthrust));

	if (!linearOnly) {
		// pitch X
		// yaw   Y
		// roll  Z
		//model center is at 0,0,0, no need for invSubModelMat stuff
		const vector3f at = vector3f(rd->angthrust);
		const vector3f angdir = pos.Cross(dir);

		const float xp = angdir.x * at.x;
		const float yp = angdir.y * at.y;
		const float zp = angdir.z * at.z;

		if (xp+yp+zp > 0) {
			if (xp > yp && xp > zp && fabs(at.x) > power) power = fabs(at.x);
			else if (yp > xp && yp > zp && fabs(at.y) > power) power = fabs(at.y);
			else if (zp > xp && zp > yp && fabs(at.z) > power) power = fabs(at.z);
		}
	}
	if (power < 0.001f) return;

	Graphics::Renderer *r = GetRenderer();
	r->SetBlendMode(Graphics::BLEND_ADDITIVE);
	r->SetDepthWrite(false);
	r->SetTransform(trans);

	m_tMat->diffuse = baseColor * power;
	//directional fade
	/*vector3f cdir(0.f, 0.f, -1.f);
	vector3f vdir(-trans[2], -trans[6], -trans[10]);
	m_tMat->diffuse.a = 1.f - Clamp(vdir.Dot(cdir), 0.f, 1.f);*/
	r->DrawTriangles(m_tVerts.Get(), m_tMat.Get());
	r->SetBlendMode(Graphics::BLEND_SOLID);
	r->SetDepthWrite(true);
}
Ejemplo n.º 26
0
    /// Renders the credits screen.
    /// @param[in,out]  renderer - The renderer to use for rendering.
    void CreditsScreen::Render(GRAPHICS::Renderer& renderer) const
    {
        // CALCULATE THE OFFSET OF THE TOP OF THE CREDITS BASED ON THE ELAPSED TIME.
        // This helps implement scrolling of the credits text upward.
        const float SCROLL_RATE_IN_PIXELS_PER_SECOND = -4.0f;
        float elapsed_time_in_seconds = ElapsedTime.asSeconds();
        float credits_text_top_offset_in_pixels = SCROLL_RATE_IN_PIXELS_PER_SECOND * elapsed_time_in_seconds;

        // RENDER TEXT INDICATING THE PURPOSE OF THIS SCREEN.
        const GRAPHICS::Color CREDITS_TEXT_COLOR = GRAPHICS::Color::WHITE;
        
        MATH::FloatRectangle screen_rectangle = renderer.Screen->GetBoundingRectangle<float>();
        float screen_left_x_position = screen_rectangle.GetLeftXPosition();
        float screen_top_y_position = screen_rectangle.GetTopYPosition();
        float screen_width_in_pixels = screen_rectangle.GetWidth();
        float screen_height_in_pixels = screen_rectangle.GetHeight();
        const float SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS = static_cast<float>(GRAPHICS::GUI::Glyph::DEFAULT_HEIGHT_IN_PIXELS);
        float credits_text_start_top_y_position = screen_top_y_position + credits_text_top_offset_in_pixels;
        MATH::FloatRectangle credits_title_text_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            credits_text_start_top_y_position,
            screen_width_in_pixels,
            SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS);

        renderer.RenderCenteredText(
            "CREDITS",
            RESOURCES::AssetId::FONT_TEXTURE,
            credits_title_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        // RENDER TEXT CREDITING GOD.
        const std::string GOD_CREDIT_TEXT = R"(Him by whom "all things were created" and "all things consist" - from Colossians 1:16-17 (KJV))";

        // Some additional spacing is added to help offset this credit text from previous text.
        float start_of_credits_top_y_position_in_pixels = 2 * SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS + credits_text_start_top_y_position;

        // This text takes multiple lines to render using the current font.
        const unsigned int GOD_CREDIT_TEXT_LINE_COUNT = 4;
        const float GOD_CREDIT_TEXT_HEIGHT_IN_PIXELS = static_cast<float>(GOD_CREDIT_TEXT_LINE_COUNT * SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS);
        MATH::FloatRectangle current_credit_text_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            start_of_credits_top_y_position_in_pixels,
            screen_width_in_pixels,
            GOD_CREDIT_TEXT_HEIGHT_IN_PIXELS);

        renderer.RenderCenteredText(
            GOD_CREDIT_TEXT,
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        // RENDER ADDITIONAL CREDITS FOR INDIVIDUAL PEOPLE.
        // Some additional spacing is added to help offset this credit text from other text.
        const float SPACING_BEFORE_REMAINING_CREDITS = (2 * SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS);
        float current_credits_text_top_y_position_in_pixels = 
            start_of_credits_top_y_position_in_pixels +
            GOD_CREDIT_TEXT_HEIGHT_IN_PIXELS +
            SPACING_BEFORE_REMAINING_CREDITS;
        current_credit_text_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            current_credits_text_top_y_position_in_pixels,
            screen_width_in_pixels,
            SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS);
        renderer.RenderCenteredText(
            "Programming - Jacob Pike",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        const MATH::Vector2f MOVE_DOWN_SINGLE_LINE(0, SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS);
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);        
        renderer.RenderCenteredText(
            "Graphics - Jacob Pike",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Music - Chad Pike",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        // RENDER ADDITIONAL CREDITS FOR SOUND EFFECTS.
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "ANIMAL SOUNDS",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "soundbible.com",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "BuffBill84",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Mike Koenig",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "snottyboy",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "NPS",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "fws.gov",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "BlastwaveFx.com",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Daniel Simion",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Caroline Ford",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "JimBob",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "J Dawg",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "wrzesien",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        // RENDER ADDITIONAL CREDITS FOR DEVELOPMENT TOOLS.
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "DEVELOPMENT TOOLS",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Visual Studio 2017",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Git/GitHub",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Microsoft Paint",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Bfxr",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Doxygen",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "SFML",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "Catch",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        // RENDER ADDITIONAL CREDITS FOR OTHER RESOURCES.
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "OTHER RESOURCES",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        current_credit_text_screen_rectangle.Move(MOVE_DOWN_SINGLE_LINE);
        renderer.RenderCenteredText(
            "KJV Bible",
            RESOURCES::AssetId::FONT_TEXTURE,
            current_credit_text_screen_rectangle,
            CREDITS_TEXT_COLOR);

        // RENDER SOME HELP TEXT TO INFORM PLAYERS HOW TO RETURN TO THE TITLE SCREEN.
        const float SCREEN_Y_POSITION_ONE_LINE_BEFORE_BOTTOM = screen_height_in_pixels - SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS;
        MATH::FloatRectangle help_text_screen_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
            screen_left_x_position,
            SCREEN_Y_POSITION_ONE_LINE_BEFORE_BOTTOM,
            screen_width_in_pixels,
            SINGLE_TEXT_LINE_HEIGHT_IN_PIXELS);
        // A black rectangle is rendered behind the text to avoid having the text overlap
        // with other text from the credits and make things hard to read.
        renderer.RenderScreenRectangle(help_text_screen_rectangle, GRAPHICS::Color::BLACK);
        renderer.RenderText(
            "[ESC] to title",
            RESOURCES::AssetId::FONT_TEXTURE,
            help_text_screen_rectangle,
            CREDITS_TEXT_COLOR);
    }
Ejemplo n.º 27
0
void StaticGeometry::DrawBoundingBox(const Aabb &bb)
{
	const vector3f min(bb.min.x, bb.min.y, bb.min.z);
	const vector3f max(bb.max.x, bb.max.y, bb.max.z);
	const vector3f fbl(min.x, min.y, min.z); //front bottom left
	const vector3f fbr(max.x, min.y, min.z); //front bottom right
	const vector3f ftl(min.x, max.y, min.z); //front top left
	const vector3f ftr(max.x, max.y, min.z); //front top right
	const vector3f rtl(min.x, max.y, max.z); //rear top left
	const vector3f rtr(max.x, max.y, max.z); //rear top right
	const vector3f rbl(min.x, min.y, max.z); //rear bottom left
	const vector3f rbr(max.x, min.y, max.z); //rear bottom right

	const Color c(Color::WHITE);

	std::unique_ptr<Graphics::VertexArray> vts(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_DIFFUSE));

	//Front face
	vts->Add(ftr, c); //3
	vts->Add(fbr, c); //1
	vts->Add(fbl, c); //0

	vts->Add(fbl, c); //0
	vts->Add(ftl, c); //2
	vts->Add(ftr, c); //3

	//Rear face
	vts->Add(rbr, c); //7
	vts->Add(rtr, c); //5
	vts->Add(rbl, c); //6

	vts->Add(rbl, c); //6
	vts->Add(rtr, c); //5
	vts->Add(rtl, c); //4

	//Top face
	vts->Add(rtl, c); //4
	vts->Add(rtr, c); //5
	vts->Add(ftr, c); //3

	vts->Add(ftr, c); //3
	vts->Add(ftl, c); //2
	vts->Add(rtl, c); //4

	//bottom face
	vts->Add(fbr, c); //1
	vts->Add(rbr, c); //7
	vts->Add(rbl, c); //6

	vts->Add(rbl, c); //6
	vts->Add(fbl, c); //0
	vts->Add(fbr, c); //1

	//left face
	vts->Add(fbl, c); //0
	vts->Add(rbl, c); //6
	vts->Add(rtl, c); //4

	vts->Add(rtl, c); //4
	vts->Add(ftl, c); //2
	vts->Add(fbl, c); //0

	//right face
	vts->Add(rtr, c); //5
	vts->Add(rbr, c); //7
	vts->Add(fbr, c); //1

	vts->Add(fbr, c); //1
	vts->Add(ftr, c); //3
	vts->Add(rtr, c); //5

	Graphics::Renderer *r = GetRenderer();

	Graphics::RenderStateDesc rsd;
	rsd.cullMode = Graphics::CULL_NONE;

	RefCountedPtr<Graphics::VertexBuffer> vb;
	//create buffer and upload data
	Graphics::VertexBufferDesc vbd;
	vbd.attrib[0].semantic = Graphics::ATTRIB_POSITION;
	vbd.attrib[0].format   = Graphics::ATTRIB_FORMAT_FLOAT3;
	vbd.attrib[1].semantic = Graphics::ATTRIB_DIFFUSE;
	vbd.attrib[1].format   = Graphics::ATTRIB_FORMAT_UBYTE4;
	vbd.numVertices = vts->GetNumVerts();
	vbd.usage = Graphics::BUFFER_USAGE_STATIC;
	vb.Reset( m_renderer->CreateVertexBuffer(vbd) );
	vb->Populate( *vts );

	r->SetWireFrameMode(true);
	r->DrawBuffer(vb.Get(), r->CreateRenderState(rsd), Graphics::vtxColorMaterial);
	r->SetWireFrameMode(false);
}
Ejemplo n.º 28
0
/// Renders the inventory GUI to the provided screen.
/// @param[in,out]  renderer - The renderer to use for rendering.
void InventoryGui::Render(GRAPHICS::Renderer& renderer) const
{
    // RENDER A RECTANGLE FOR THE BACKGROUND.
    // It is offset from the top of the screen by the amount of the
    // top row of the HUD that is always displayed.  Otherwise,
    // it should cover the remainder of the screen.
    const float TOP_SCREEN_OFFSET_IN_PIXELS = static_cast<float>(GRAPHICS::GUI::Glyph::HEIGHT_IN_PIXELS);
    const float SCREEN_LEFT_POSITION_IN_PIXELS = 0.0f;
    const float BACKGROUND_HEIGHT_IN_PIXELS = renderer.Screen.HeightInPixels<float>() - TOP_SCREEN_OFFSET_IN_PIXELS;
    MATH::FloatRectangle background_rectangle = MATH::FloatRectangle::FromLeftTopAndDimensions(
                SCREEN_LEFT_POSITION_IN_PIXELS,
                TOP_SCREEN_OFFSET_IN_PIXELS,
                renderer.Screen.WidthInPixels<float>(),
                BACKGROUND_HEIGHT_IN_PIXELS);

    // The background color is currently arbitrary.
    GRAPHICS::Color background_color;
    background_color.Red = GRAPHICS::Color::MAX_COLOR_COMPONENT;
    background_color.Green = GRAPHICS::Color::MAX_COLOR_COMPONENT;
    background_color.Blue = GRAPHICS::Color::MAX_COLOR_COMPONENT;
    renderer.RenderScreenRectangle(
        background_rectangle,
        background_color);

    // RENDER A TAB FOR THE BIBLE PORTION OF THE GUI.
    // It should be positioned near the top-left of the GUI.
    float bible_tab_left_screen_position_in_pixels = background_rectangle.GetLeftXPosition();
    float bible_tab_top_screen_position_in_pixels = background_rectangle.GetTopYPosition();
    MATH::Vector2f bible_tab_left_top_screen_position_in_pixels(
        bible_tab_left_screen_position_in_pixels,
        bible_tab_top_screen_position_in_pixels);
    RenderTab(
        "Bible",
        bible_tab_left_top_screen_position_in_pixels,
        InventoryBiblePage::BACKGROUND_COLOR,
        renderer);

    // RENDER A TAB FOR THE ANIMAL PORTION OF THE GUI.
    const std::string ANIMALS_TAB_STRING = "Animals";
    unsigned int animals_tab_text_width_in_pixels = GRAPHICS::GUI::Glyph::WIDTH_IN_PIXELS * ANIMALS_TAB_STRING.length();
    unsigned int animals_tab_text_half_width_in_pixels = animals_tab_text_width_in_pixels / 2;
    float animals_tab_left_screen_position_in_pixels = background_rectangle.GetCenterXPosition() - animals_tab_text_half_width_in_pixels;
    float animals_tab_top_screen_position_in_pixels = background_rectangle.GetTopYPosition();
    MATH::Vector2f animals_tab_left_top_screen_position_in_pixels(
        animals_tab_left_screen_position_in_pixels,
        animals_tab_top_screen_position_in_pixels);
    RenderTab(
        ANIMALS_TAB_STRING,
        animals_tab_left_top_screen_position_in_pixels,
        ANIMALS_TAB_COLOR,
        renderer);

    // RENDER A TAB FOR THE FOOD PORTION OF THE GUI.
    const std::string FOOD_TAB_STRING = "Food";
    unsigned int food_tab_text_width_in_pixels = GRAPHICS::GUI::Glyph::WIDTH_IN_PIXELS * FOOD_TAB_STRING.length();
    float food_tab_left_screen_position_in_pixels = background_rectangle.GetRightXPosition() - food_tab_text_width_in_pixels;
    float food_tab_top_screen_position_in_pixels = background_rectangle.GetTopYPosition();
    MATH::Vector2f food_tab_left_top_screen_position_in_pixels(
        food_tab_left_screen_position_in_pixels,
        food_tab_top_screen_position_in_pixels);
    RenderTab(
        FOOD_TAB_STRING,
        food_tab_left_top_screen_position_in_pixels,
        FOOD_TAB_COLOR,
        renderer);

    // RENDER THE CURRENTLY DISPLAYED PAGE.
    switch (CurrentTab)
    {
    case TabType::BIBLE:
        BiblePage.Render(renderer);
        break;
    case TabType::ANIMALS:
        RenderAnimalsPage(renderer);
        break;
    case TabType::FOOD:
        RenderFoodPage(renderer);
        break;
    }
}
Ejemplo n.º 29
0
int main(int argc, char **argv)
{
	FileSystem::Init();

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "sdl init failed: %s\n", SDL_GetError());
		exit(-1);
	}

    const SDL_VideoInfo *info = SDL_GetVideoInfo();
    switch (info->vfmt->BitsPerPixel) {
        case 16:
            SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
            SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
            SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
            break;
        case 24:
        case 32:
            SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
            SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
            SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
            break;
        default:
            fprintf(stderr, "invalid pixel depth: %d bpp\n", info->vfmt->BitsPerPixel);
            exit(-1);
    }
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);

	SDL_Surface *surface = SDL_SetVideoMode(WIDTH, HEIGHT, info->vfmt->BitsPerPixel, SDL_OPENGL);
	if (!surface) {
		fprintf(stderr, "sdl video mode init failed: %s\n", SDL_GetError());
		SDL_Quit();
		exit(-1);
	}

	SDL_WM_SetCaption("textstress", "textstress");

	Graphics::Settings videoSettings;
	videoSettings.width = WIDTH;
	videoSettings.height = HEIGHT;
	videoSettings.fullscreen = false;
	videoSettings.shaders = false;
	videoSettings.requestedSamples = 0;
	videoSettings.vsync = false;
	videoSettings.useTextureCompression = false;
	Graphics::Renderer *r = Graphics::Init(videoSettings);

	r->SetOrthographicProjection(0, WIDTH, HEIGHT, 0, -1, 1);
	r->SetTransform(matrix4x4f::Identity());
	r->SetClearColor(Color::BLACK);
	r->SetBlendMode(Graphics::BLEND_ALPHA);
	r->SetDepthTest(false);

	const Text::FontDescriptor fontDesc(Text::FontDescriptor::Load(FileSystem::gameDataFiles, "fonts/UIFont.ini", "English"));
	Text::TextureFont *font = new Text::TextureFont(fontDesc, r);

	std::string str;
	for (int i = 33; i < 127; i++)
		str.push_back(i);

	while (1) {
		bool done = false;

		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
				done = true;
		}
		if (done)
			break;

		font->RenderString(str.c_str(), rand()%(WIDTH*2)-WIDTH, rand()%HEIGHT, Color::WHITE);
		r->SwapBuffers();
	}

	delete font;
	delete r;

	SDL_Quit();

	exit(0);
}
Ejemplo n.º 30
0
void Shields::ReparentShieldNodes(SceneGraph::Model* model)
{
	assert(s_initialised);

	Graphics::Renderer *renderer = model->GetRenderer();

	using SceneGraph::Node;
	using SceneGraph::Group;
	using SceneGraph::MatrixTransform;
	using SceneGraph::StaticGeometry;

	//This will find all matrix transforms meant for navlights.
	SceneGraph::FindNodeVisitor shieldFinder(SceneGraph::FindNodeVisitor::MATCH_NAME_ENDSWITH, "_shield");
	model->GetRoot()->Accept(shieldFinder);
	const std::vector<Node*> &results = shieldFinder.GetResults();

	//Move shield geometry to same level as the LODs
	for (unsigned int i = 0; i < results.size(); i++) {
		MatrixTransform *mt = dynamic_cast<MatrixTransform*>(results.at(i));
		assert(mt);

		const Uint32 NumChildren = mt->GetNumChildren();
		if (NumChildren>0)
		{
			// Group to contain all of the shields we might find
			Group *shieldGroup = new Group(renderer);
			shieldGroup->SetName(s_shieldGroupName);

			// go through all of this MatrixTransforms children to extract all of the shield meshes
			for (Uint32 iChild = 0; iChild < NumChildren; ++iChild) {
				Node* node = mt->GetChildAt(iChild);
				assert(node);
				if (node)
				{
					RefCountedPtr<StaticGeometry> sg(dynamic_cast<StaticGeometry*>(node));
					assert(sg.Valid());
					sg->SetNodeMask(SceneGraph::NODE_TRANSPARENT);

					// We can early-out if we've already processed this models scenegraph.
					if (Graphics::BLEND_ALPHA == sg->m_blendMode) {
						assert(false);
					}

					// force the blend mode
					sg->m_blendMode = Graphics::BLEND_ALPHA;

					Graphics::RenderStateDesc rsd;
					rsd.blendMode = Graphics::BLEND_ALPHA;
					rsd.depthWrite = false;
					sg->SetRenderState(renderer->CreateRenderState(rsd));

					for (Uint32 iMesh = 0; iMesh < sg->GetNumMeshes(); ++iMesh) {
						StaticGeometry::Mesh &rMesh = sg->GetMeshAt(iMesh);
						rMesh.material = GetGlobalShieldMaterial();
					}

					// find the accumulated transform from the root to our node
					MatrixAccumVisitor mav(mt->GetName());
					model->GetRoot()->Accept(mav);

					// set our nodes transformation to be the accumulated transform
					MatrixTransform *sg_transform_parent = new MatrixTransform(renderer, mav.outMat);
					std::stringstream nodeStream;
					nodeStream << iChild << s_matrixTransformName;
					sg_transform_parent->SetName(nodeStream.str());
					sg_transform_parent->AddChild(sg.Get());

					// dettach node from current location in the scenegraph...
					mt->RemoveChild(node);

					// attach new transform node which parents the our shields mesh to the shield group.
					shieldGroup->AddChild(sg_transform_parent);
				}
			}

			model->GetRoot()->AddChild(shieldGroup);
		}
	}
}