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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - racumin

Pages: [1] 2
1
Graphics / Outline inside of Shape::Rectangle
« on: November 27, 2009, 09:12:20 am »
Ok thanks

2
Graphics / Outline inside of Shape::Rectangle
« on: November 27, 2009, 08:45:47 am »
Hi, how do I put the border (outline) of a Shape::Rectangle inside the rectangle itself?

Code: [Select]

sf::Shape rect = sf::Shape::Rectangle(0, 0, 50, 50,<color_here>, 2.0f, <color_here>);


In this code, the output was a rectangle with size 50 and its border 2.0f. making the whole rectangle bigger (with size 52). I want to just make the rectangle 50 and its "inner" border 2. Is there any method to do it?

Of course I can just recompute so that the total size is always fixed but I just want to know if this is already implemented. Thanks!

3
Window / Delayed display on Windows
« on: October 21, 2009, 12:36:25 pm »
Thanks for the answers. So, I am assured that the whole loop will just be called at most 60 times per second because of the Sleep in the window.Display().

Now, I explored my code and noticed that a single draw method was enough to boost my cpu usage to about 20 - 30. In my loop, I just did this:

Code: [Select]

Shape blocksPanel = Shape::Rectangle(
(GRID_WIDTH + 2) * BLOCK_SIZE,
BLOCK_SIZE * 8,
(GRID_WIDTH + 7) * BLOCK_SIZE,
(GRID_HEIGHT_LIMIT + 1) * BLOCK_SIZE,
BG_COLOR,
OUTLINE,
OUTLINE_COLOR);
window->Draw(blocksPanel);


Is this acceptable? Is the CPU usage of 50 acceptable when running a simple application? By the way, I used a pointer for the RenderWindow

Code: [Select]

RenderWindow *window;
VideoMode mode(GUI_WIDTH, GUI_HEIGHT, 32);
window = new RenderWindow(mode, "Falling Blocks", Style::Close);


Does that affect the performance of the application?

[edit] Hmmm. I think that my PC is responsible for the slow display. I tried my program in a different computer and it runs smoothly.

Thanks anyways...

4
Window / Delayed display on Windows
« on: October 21, 2009, 11:58:29 am »
Hi I tried to look for the problem here. The reason (I think) that displaying was delayed was because when I play the game, the CPU usage for it was about 50. (using ctrl + alt + delete). The psuedo code here is

Code: [Select]

int main() {
   Gui gui;

   while (gui.isRunning()) {
      gui.clearBackground();      // window.clear()
      gui.defaultMove();          // move the object 1 space down
      gui.handleEvents();        // the while loop i saw in the tutorials
      gui.drawGamePanel();        // draw objects here
      gui.display();               // window.display()
   }
   return 0;
}



Now, I commented all the logic stuffs like this:

Code: [Select]

int main() {
   Gui gui;

   while (gui.isRunning()) {
      gui.clearBackground();      // window.clear()
 //     gui.defaultMove();          // move the object 1 space down
      gui.handleEvents();        // the while loop i saw in the tutorials
 //     gui.drawGamePanel();        // draw objects here
      gui.display();               // window.display()
   }
   return 0;
}


The CPU then was 0, meaning I have a bug in the program. So, what I thought to be the problem was that the loop never sleeps. I assumed that window.display() with frame limit = 60 will do the job but it did not. The other methods were called every loop (loop was called maybe several times a millisecond??)

So I tried to put a sleep in my code:

Code: [Select]

int main() {
   Gui gui;

   while (gui.isRunning()) {
      Sleep(0.001f);
      gui.clearBackground();      // window.clear()
      gui.defaultMove();          // move the object 1 space down
      gui.handleEvents();        // the while loop i saw in the tutorials
      gui.drawGamePanel();        // draw objects here
      gui.display();               // window.display()
   }
   return 0;
}


It also failed. CPU was also about 50. Now for questions

1. How does the window.display() with window.setFrameLimit(60) work?
2. If you set the frame limit to 60, do you still need to draw ALL objects in the canvas? (window.Draw(Rectangle))
3. Do I really need to put a Sleep() in every loop? If so, what can be its value?
4. The output was also seen in the console. Does this matter? If so, how can I disable output from console? (using windows and code::blocks)

Thanks!

[edit] I was able to disable the output from console using -mwindows but it still consumes a lot of CPU (about 50)

5
Window / Delayed display on Windows
« on: October 14, 2009, 09:37:32 am »
What do you mean by complete and minimal example? Do you mean the source code?

6
Window / Delayed display on Windows
« on: October 14, 2009, 09:22:15 am »
How can I upload the exe?

These are my code snippets

Code: [Select]

void Gui::handleEvents() {
//listen for events
Event event;
while (window->GetEvent(event)) {
// a key is pressed
if (event.Type == Event::KeyPressed) {
switch (event.Key.Code) {
case Key::Escape:
if (gameStatus == STATUS_PLAYING) {
cout << "pausing game..." << endl;
gameStatus = STATUS_PAUSED;
} else if (gameStatus == STATUS_PAUSED) {
cout << "resuming game..." << endl;
gameStatus = STATUS_PLAYING;
} else {
cout << "closing window..." << endl;
running = false;
window->Close();
}

break;
case Key::Left:
if (gameStatus == STATUS_PLAYING) {
current_shape->moveLeft();
}
break;
case Key::Right:
if (gameStatus == STATUS_PLAYING) {
current_shape->moveRight();
}
break;
case Key::Down:
if (gameStatus == STATUS_PLAYING) {
moveDown();
}
break;
case Key::Space:
if (gameStatus == STATUS_PLAYING) {
current_shape->rotateClockwise();
}
break;

default:
cout << "ignoring pressed key..." << endl;
}
} else if (event.Type == Event::Closed) {
cout << "pressed close button, closing window..." << endl;
running = false;
window->Close();
}
}
}


One more thing, I am using the Clock class to determine if the current object should be moved down.

Code: [Select]


void Gui::defaultMove() {
//move shape down if status is STATUS_PLAYING
if ((clock.GetElapsedTime() >= sleepTime) && (gameStatus == STATUS_PLAYING)) {
clock.Reset();
moveDown();
}
}


My sleepTime is 1.0f and it decreases as the game level progresses

7
General / Code::Blocks generating an executable
« on: October 14, 2009, 09:17:38 am »
Hi, I created a simple game and I want to deploy it to other PC. In Code::Blocks, how do I disabled the console when running the app? When I go to the Release folder and run the exe file, it produces the main window app but also the console, I want to disable the console. Thanks!

Another question, if I copy the directory of the Release and paste it in another PC wihtout Code::Blocks installed, will it run? (please do not say "try it and see for your self" - I do not have any other PC and I do not want to uninstall Code::Blocks from this computer then try it then install again) Thanks again!

8
Window / Delayed display on Windows
« on: October 14, 2009, 05:25:50 am »
I am making a simple tetris game and developed my program in Linux. It runs smoothly - when I press a button, the state of the objects are displayed instantly. But when I compiled my code in Windows, the display is delayed. For example I pressed the left key 4 times, after some milliseconds (but I think less than a second), the object was moved 4 spaces already. In linux I can see it move 1 space every time I press the key. Why is that? The logic I used was:

Code: [Select]

int main() {
Gui gui;

while (gui.isRunning()) {
gui.clearBackground();      // window.clear()
gui.defaultMove();          // move the object 1 space down
gui.handleEvents();        // the while loop i saw in the tutorials
gui.drawGamePanel();        // draw objects here
gui.display();               // window.display()
}
return 0;
}


By the way, I initialized my window using:
Code: [Select]

VideoMode mode(GUI_WIDTH, GUI_HEIGHT, 32);
window = new RenderWindow(mode, "Falling Blocks", Style::Close);
window->SetFramerateLimit(60);

Image img_icon;
img_icon.LoadFromFile("icon.png");
window->SetIcon( img_icon.GetWidth(), img_icon.GetHeight(), img_icon.GetPixelsPtr());

if (!font.LoadFromFile("myfont.ttf")) {
cout << "failed to load font" << endl;
return;
}


Any ideas? Thanks!

[edit] Ok, I was able to disable the output from console using the option -mwindows But it still has a CPU usage of about 50.

9
Graphics / Can't Use sf::Strings.
« on: October 13, 2009, 01:37:57 pm »
Quote from: "Laurent"
It's fixed in the sfml2 branch. It's not fixed in SFML 1.x because it requires a rewrite of the OpenGL context handling.

There are two very simple workarounds:
- link to the static versions of the SFML libraries
- always provide your own sf::Font when instanciating a sf::String


How do I provide my own sf::Font when instanciating a String? Also in Visual C++ I do not know how to link the static versions. It says unresolved symbol. Thanks!

10
Window / No title bar on RenderWindow
« on: October 12, 2009, 10:50:33 am »
Hi thanks for the solution! I disabled the visual effects  and now the title bar is displayed. Thank you very much!!!!

11
Window / No title bar on RenderWindow
« on: October 12, 2009, 10:09:41 am »
It's Compiz.

12
Window / No title bar on RenderWindow
« on: October 12, 2009, 04:22:02 am »
Hi, I tried the following code. It produces a screen with 100 x 150 pixels. But the problem is, I cannot see the title bar. But when I try to click the area where the close button should be located, it prints "closing", meaning that the handling of events function correctly but the title bar really won't show. I'm using Ubuntu Hardy.

Code: [Select]

int main() {

cout << "Starting..." << endl;

WindowSettings settings;
settings.DepthBits = 32;
settings.StencilBits = 8;
settings.AntialiasingLevel = 2;

VideoMode mode(100, 150, 32);
RenderWindow window(mode, "SFML Window", Style::Close, settings);
window.SetFramerateLimit(60);

while (window.IsOpened() && running) {

window.Clear();

//listen for events
Event event;
while (window.GetEvent(event)) {
// a key is pressed
if (event.Type == Event::KeyPressed) {

} else if (event.Type == Event::Closed) {
cout << "closing" << endl;
}
}

window.Display();
}
cout << "Exiting..." << endl;

return EXIT_SUCCESS;

}

13
Window / No title bar on RenderWindow
« on: October 09, 2009, 09:00:42 am »
Hi, for now, I think the call to GetEvent is not neccessary. From the link above, you can see in its screenshot that there is a window with black background and a title bar with the "iiiiSkipBo" text. There is also a minimize, maximize and close buttons. When I ran this program in Ubuntu, it produces some black pixels with no window at all.

If I am wrong, please correct me. If I need to call the GetEvent, what will I do there? Is it something like
Code: [Select]

    while (App.GetEvent(Event))
    {
        if (Event.Type == sf::Event::window_opened??)
            //display titlebar here
    }


Thanks!

14
Window / No title bar on RenderWindow
« on: October 08, 2009, 10:25:42 am »
Hi I think the problem is cause by the Ubuntu OS. I tried the code from http://www.sfml-dev.org/forum/viewtopic.php?t=1257&highlight=title and when I ran it, no window was displayed. How do I fix that?

15
Window / No title bar on RenderWindow
« on: October 08, 2009, 09:12:35 am »
I just need to see the title bar for my window. How do I make the window show the title bar? How will I do this using the GetEvent method?

Pages: [1] 2