Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [help] Blank terminal window running latest SFML & minGW  (Read 2346 times)

0 Members and 1 Guest are viewing this topic.

Servious

  • Newbie
  • *
  • Posts: 3
    • View Profile
[help] Blank terminal window running latest SFML & minGW
« on: November 26, 2011, 11:42:35 am »
I have Code::Blocks 10.5 and SFML 1.6. I am making a simple program that gets 3 points from the user and prints out a triangle and the area as well as a few other things to the screen. Every time I run it, all I get is a blank terminal window.
Here is my code:
Code: [Select]
#include <iostream>
#include <math.h>
#include <sstream>
#include <SFML/Graphics.hpp>

using namespace std;

class triangle
{
    void sort();
public:
    triangle(int x1, int y1, int x2, int y2, int x3, int y3)
    {
        x[0] = x1;
        x[1] = x2;
        x[2] = x3;
        y[0] = y1;
        y[1] = y2;
        y[2] = y3;

        /////////
        //sides//
        /////////

        for (int i = 0; i < 3; i++)
        {
            if (i < 2)
            {
                side[i] = sqrt(((x[i + 1] - x[i]) * (x[i + 1] - x[i])) + ((y[i + 1] - y[i]) * (y[i + 1] - y[i])));
            }else
            {
                side[i] = sqrt(((x[0] - x[i]) * (x[0] - x[i])) + ((y[0] - y[i]) * (y[0] - y[i])));
            }
        }

        ////////
        //area//
        ////////

        float s;
        for (int i = 0; i < 3; i++)
        {
            if (side[i] < 0)
            {
                side[i] = -side[i];
            }
        }
        s = (side[0] + side[1] + side[2]) / 2;
        area = sqrt(s * (s - side[0]) * (s - side[1]) * (s - side[2]));

        /////////////////////
        //angles (oh, god.)//
        /////////////////////

        sort();
        float tempo = 0;
        float temop2 = 0;
        tempo = ((side[0] * side[0]) + (side[1] * side[1]) - (side[2] * side[2])) / (2 * side[0] * side[1]);
        tempo = acos(tempo);
        angle[0] = tempo * (180 / M_PI);
        temop2 = sin(tempo);
        tempo = (side[0] * temop2) / side[2];
        temop2 = asin(tempo);
        angle[1] = temop2 * (180 / M_PI);
        angle[2] = 180 - (angle[0] + angle[1]);
        for (int i = 0; i < 3; i++)
        {
            if (angle[i] == 90)
            {
                right = true;
            }
        }//0 sin 2  base = 3

        //////////////////////////////////////////////
        //height of ONE side. Not gonna do the rest.//
        //////////////////////////////////////////////

        height = side[0] * sin(angle[2] * (M_PI / 180));
    }
    float angle[3];
    float side[3];
    float x[3];
    float y[3];
    float area;
    float height;
    bool right;
};

void triangle::sort()
{
    int temp;
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            if (side[j] > side[j + 1])
            {
                temp = side[j];
                side[j] = side[j + 1];
                side[j + 1] = temp;
                temp = 0;
            }
        }
    }
    //3 2 1 -> 1 2 3
}

string conv(float var)
{
    float i = var;
    string s;
    stringstream out;
    out << i;
    s = out.str();
    return s;
}

int main()
{
    int points[3][2];
    sf::Font MyFont;
    if (!MyFont.LoadFromFile("E:/fdsa/pirulen.ttf"))
    {
        // Error...
    }
    for (int i = 0; i < 3; i++)
    {
        cout << "point set " << i + 1 << endl;
        for (int j = 0; j < 2; j++)
        {
            if (j == 0)
            {
                cout << "X:";
            }
            if (j == 1)
            {
                cout << "Y:";
            }
            cin >> points[i][j];
        }
    }
    triangle tri(points[0][0], points[0][1], points[1][0], points[1][1], points[2][0], points[2][1]);
    sf::String Right("Right: ", MyFont, 14);
    sf::String A(conv(tri.angle[0]) + "°", MyFont, 14);
    sf::String B(conv(tri.angle[1]) + "°", MyFont, 14);
    sf::String C(conv(tri.angle[2]) + "°", MyFont, 14);
    Right.Move(0.f, 580.f);
    if (tri.right == true)
    {
        Right.SetText("Right: true. Area: " + conv(tri.area));
    }
    if (tri.right != true)
    {
        Right.SetText("Right: false. Area: " + conv(tri.area));
    }
    A.Move(tri.x[1], tri.y[1] + 10);
    B.Move(tri.x[2], tri.y[2] + 10);
    C.Move(tri.x[0], tri.y[0] + 10);
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
    while (App.IsOpened())
    {
        sf:: Event Event;

        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
            {
                App.Close();
            }
        }
        App.Clear();
        App.Draw(sf::Shape::Line(tri.x[0]/* x1 */, tri.y[0]/* y1 */, tri.x[1]/* x2 */, tri.y[1]/* y2 */, 3, sf::Color::White, 0, sf::Color::Black));
        App.Draw(sf::Shape::Line(tri.x[1]/* x2 */, tri.y[1]/* y2 */, tri.x[2]/* x3 */, tri.y[2]/* y3 */, 3, sf::Color::White, 0, sf::Color::Black));
        App.Draw(sf::Shape::Line(tri.x[0]/* x1 */, tri.y[0]/* y1 */, tri.x[2]/* x3 */, tri.y[2]/* y3 */, 3, sf::Color::White, 0, sf::Color::Black));
        App.Draw(Right);
        App.Draw(A);
        App.Draw(B);
        App.Draw(C);
        App.Display();
    }
    return EXIT_SUCCESS;
}

I have tried this on another computer with the same versions of Code::Blocks and SFML, and it worked. Why doesn't it work on my computer? No error msgs at all.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[help] Blank terminal window running latest SFML & minGW
« Reply #1 on: November 26, 2011, 12:05:31 pm »
ATI graphics card?
Laurent Gomila - SFML developer

Servious

  • Newbie
  • *
  • Posts: 3
    • View Profile
[help] Blank terminal window running latest SFML & minGW
« Reply #2 on: November 26, 2011, 12:10:02 pm »
Quote from: "Laurent"
ATI graphics card?

AMD. Running Windows 7. Persario CQ-61. If that helps. :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[help] Blank terminal window running latest SFML & minGW
« Reply #3 on: November 26, 2011, 12:17:44 pm »
SFML 1.6 doesn't work on Windows with ATI drivers. Use either the static version of SFML, or SFML 2.
Laurent Gomila - SFML developer

Servious

  • Newbie
  • *
  • Posts: 3
    • View Profile
[help] Blank terminal window running latest SFML & minGW
« Reply #4 on: November 26, 2011, 12:22:10 pm »
Quote from: "Laurent"
SFML 1.6 doesn't work on Windows with ATI drivers. Use either the static version of SFML, or SFML 2.

How do I setup static SFML? Could I get a link?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer