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 - olie258

Pages: [1]
1
Java / Re: Obligatory 'loading resources on a thread' post.
« on: January 31, 2013, 12:13:40 am »
Thanks, guys, for the speedy replies. OpenGL is not my area of expertise so I really appreciate the assistance.

pdinklag - if you're able to repro the problem and you make any progress towards solving it I'd be eager to hear about it. Thank you for looking into it.

Even though Laurent has said it's a no-no, I tried out the Context instance solution this evening (just for science), and I was eventually able to get it working by calling setActive(true) then creating the Texture and finally calling setActive(false). Something like:

public void run() {
        Context context = new Context();
       
        try {
                context.setActive(true);
                Texture texture = new Texture();
                texture.loadFromFile(Paths.get("canyonlands_large.jpg"));
                context.setActive(false);
                                       
                cache.put(KEY, texture);

        } catch (Exception e) {
                e.printStackTrace();
        }      
}

Just thought I'd share incase the information is useful in any way.

2
Java / Obligatory 'loading resources on a thread' post.
« on: January 29, 2013, 10:49:26 pm »
Hello there,

I'm attempting to use a worker thread load textures and subsequently use these textures on the main thread but I'm running into a problem, specifically that these textures do not appear to be rendering.

I've included a minimal example that reproduces the problem below. I wonder if anyone can provide some insight into what may be going wrong here?

I'm using the January 29th JSFML test release on Windows (64 bit) with Intel HD Graphics 4000 integrated graphics.

import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.ConcurrentHashMap;

import org.jsfml.graphics.*;
import org.jsfml.window.*;
import org.jsfml.window.event.Event;

public class Example {
        // Texture cache
        public static final ConcurrentHashMap<String, ConstTexture> cache =
                new ConcurrentHashMap<String, ConstTexture>();
       
        private static final String KEY = "key_string";
               
        public static void main(String[] args) {
                // Initialise window
                RenderWindow renderWindow = new RenderWindow();
                renderWindow.create(new VideoMode(800, 600), "Eg.");
               
                // On another thread, create a Texture from an image file then cache it
                Thread worker = new Thread(new Runnable() {
                        public void run() {
                                Texture texture = new Texture();
                                try {
                                        texture.loadFromFile(Paths.get("canyonlands_large.jpg"));
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
                                cache.put(KEY, texture);
                        }
                });
               
                worker.start();
                               
                // Wait for the image to be loaded and
                while (worker.isAlive()) {
                        //...Show loading screen...
                }
               
                // Create a sprite using the loaded texture
                Sprite sprite = new Sprite(cache.get(KEY));
               
                // Main loop
                while (renderWindow.isOpen()) {
                        // Handle events
                        for (Event e : renderWindow.pollEvents()) {
                                if (e.type == Event.Type.CLOSED)
                                        renderWindow.close();
                        }
                       
                        // Draw sprite
                        renderWindow.clear(Color.BLACK);
                        renderWindow.draw(sprite);
                        renderWindow.display();
                }
        }
}

3
General / RenderWindow::PollEvent + mouse movement problem
« on: November 04, 2011, 09:41:50 pm »
Ah, should have spotted that thread myself. I haven't tried the fix yet but that looks promising (I'll report back if it doesn't work). Thanks for the help.

4
General / RenderWindow::PollEvent + mouse movement problem
« on: November 04, 2011, 08:48:40 pm »
Hi, Laurent,

Thanks for the speedy reply. I'm not entirely sure what is meant by a 'high resolution mouse", but according to this page on Logitech's site the DPI is 1000. It certainly wasn't sold as high performance kit, just your average, cheapish keyboard/mouse combo.

I have a joystick (an Xbox 360 controller connected via a wireless adaptor) but this hasn't been powered up or connected whilst running the application. The driver does run a process in the background though.

Cheers,
Olie.

5
General / RenderWindow::PollEvent + mouse movement problem
« on: November 04, 2011, 08:03:00 pm »
Hi guys,

I ported the game I'm working on to SFML 2.0 today (from version 1.6) and I'm seeing a problem that was not happening before. When the mouse cursor is moved over my application's window the framerate drops noticeably and sometimes the application actually freezes while the cursor is moving (in these cases the application resumes as normal once the mouse is still again but with one really long frame).

The problem occurs regardless of whether v-sync is enabled, in both full screen and windowed modes. I'm using the latest development snapshot of SFML 2.0 (downloaded yesterday) and I have been able to reproduce this problem.

The only solution I've found is to remove the call to PollEvent from my game loop.
Before (problem occurs):
Code: [Select]
void Game::start()
{
while (pMainWindow->IsOpened())
{
// handle window events
sf::Event e;
while (pMainWindow->PollEvent(e))
{
if (e.Type == sf::Event::Closed)
{
pMainWindow->Close();
}
}

update();
draw();
}
}

After (works as normal):
Code: [Select]
void Game::start()
{
while (running)
{
update();
draw();
}
}


Without the call to PollEvent the application runs just as it did when on 1.6 (except for closing, of course). I'm wondering whether this is a bug or am I now using something incorrectly? Any suggestions would be much appreciated.

If anyone's interested here's my minimal recreation of the issue (although I've got a feeling that this would be known if it was a problem for everyone). When I run this code the speed at which the circle moves can be seen to drop whenever the mouse is over the window and is moved.

Code: [Select]
#include <SFML\Graphics.hpp>

int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML 2");
sf::Shape shape = sf::Shape::Circle(sf::Vector2f(0, 300), 40, sf::Color::Blue);

int x = 0;

while (Window.IsOpened())
{
sf::Event e;
while (Window.PollEvent(e))
{
if (e.Type == sf::Event::Closed)
{
Window.Close();
}
}

Window.Clear(sf::Color(107, 101, 237));

shape.SetX(x++ % 800);

Window.Draw(shape);
Window.Display();
}

return 0;
}

Pages: [1]