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

Pages: [1] 2
1
Graphics / Re: [SFML.Net] SFML.Graphics.Font no textures loading.
« on: May 18, 2014, 02:01:05 pm »
I..
Umm..
Oh. My. God.

Thank you very much, sir  :-[

Err, still. I know that assuming that myTextures refers to the textures in a font is being evil because assuming the value of private members isn't reliable. But why is the count zero for it? What's it really for? o.0

2
Graphics / Re: [SFML.Net] SFML.Graphics.Font no textures loading.
« on: May 18, 2014, 01:22:32 pm »
SFML.Net 2.0 64 and 32 bit show zero textures on fonts loaded, too.
using System;
using SFML.Graphics;
using SFML.Window;

namespace AI_CTF {
        class Program {
                static void Main (string[] args) {
                        RenderWindow rw = new RenderWindow(
                                VideoMode.DesktopMode,
                                "RenderWindow"
                        );
                        Font f = new Font("res/font/arial.ttf");
                        Text t = new Text("Text", f);

                        rw.Closed += (object sender, EventArgs e) => {
                                rw.Close();
                        };
                        while (rw.IsOpen()) {
                                rw.DispatchEvents();
                                rw.Clear();
                                t.Draw(rw, new RenderStates());
                                rw.Display();
                        }
                }
        }
}

@G, I duno. I would think it would've thrown an exception if it couldn't load a library =/

3
Graphics / Re: [SFML.Net] SFML.Graphics.Font no textures loading.
« on: May 18, 2014, 11:43:17 am »
What I posted is the exact thing I have.
using SFML.Graphics;

namespace AI_CTF {
        class Program {
                static void Main (string[] args) {
                        Font f = new Font("res/font/arial.ttf");
                }
        }
}

If it helps, I've used both the 64 and 32 bit versions of SFML.Net 2.1 and set the build target accordingly but both get me zero textures on the font.

4
Graphics / [SFML.Net] SFML.Graphics.Font no textures loading.
« on: May 18, 2014, 09:44:40 am »
Okay, so, I downloaded SFML.Net and got to some basic stuff first and drew a circle on a RenderWindow easily. Then, I tried Text and got stuck.

Basically, I've tried two custom fonts and the default Arial font from the system fonts folder without success. I think I know what's wrong but I don't know what's causing it.

I have attached a screenshot of the source code. f.myTextures.Count is always zero for some reason. And that means I can't draw any text.. But I don't know *why* it isn't getting any textures.

public void run () {
    Font f = new Font("res/font/arial.ttf");
}

5
Graphics / Re: Blocking main thread causes failed texture load
« on: July 18, 2013, 05:39:29 am »
Whoops, I came up with this instead =x
#include "Shlwapi.h"
    /*snip*/
    WCHAR szDir [260] = {0};
    GetModuleFileName(GetModuleHandle(NULL), &szDir[0], 260);
    PathRemoveFileSpec(&szDir[0]);
    /*snip*/
    opendialog.lpstrInitialDir = &szDir[0];
    /*snip*/
 
With this, the initial directory that the OFD is on is also changed, though =/

I'll look into Get and Set Current Directory, thanks!

About the thread stuff.. I have to admit I haven't done any actual threading for, like, over a year (and I never got into it =/). I remember many headaches with threading. It still scars me.

6
Graphics / Re: Blocking main thread causes failed texture load
« on: July 18, 2013, 05:13:10 am »
I was just about to write a multi-threaded test.
WCHAR szFile[260] = {0};

void threadOFD () {
    OPENFILENAME opendialog = {0};
   

    opendialog.lStructSize = sizeof (opendialog);
    opendialog.hwndOwner = NULL;
    opendialog.hInstance = GetModuleHandle(NULL);
    opendialog.lpstrFile = &szFile[0];
    opendialog.nFilterIndex = 0;
    opendialog.nMaxFile = 256;
    opendialog.lpstrInitialDir = NULL;
    opendialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    //This call blocks the main thread; blocking causes texture loading to fail
    GetOpenFileName(&opendialog);
}

int main () {
    sf::Thread thread(&threadOFD);
    thread.launch();

    //while (szFile[0] == '\0') {}

    sf::Texture t1;
    while (!t1.loadFromFile("sfml-logo-small.png")) {
        std::cout<<"Failed to load t1"<<std::endl;
    }
    std::cout<<"SUCCESS"<<std::endl;

    return 0;
}
 
When the while-loop is commented:
01) Console opens
02) OFD opens
03) Texture loads
04) Outputs success
05) OFD closes
06) Application closes

When I un-comment the while-loop:
01) Console opens
02) OFD opens
03) Texture fails to load
04) Loop 03

Absolute paths don't work, either. Well, they work BUT they don't work right.
int main () {
    OPENFILENAME opendialog = {0};
    WCHAR szFile[260] = {0};

    opendialog.lStructSize = sizeof (opendialog);
    opendialog.hwndOwner = NULL;
    opendialog.hInstance = GetModuleHandle(NULL);
    opendialog.lpstrFile = &szFile[0];
    opendialog.nFilterIndex = 0;
    opendialog.nMaxFile = 256;
    opendialog.lpstrInitialDir = NULL;
    opendialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    //This call blocks the main thread; blocking causes texture loading to fail
    GetOpenFileName(&opendialog);

    sf::Texture t1;
    while (!t1.loadFromFile("C:\\Users\\acer\\Desktop\\document.png")) {
        std::cout<<"Failed to load t1"<<std::endl;
    }
    sf::Texture t2;
    while (!t2.loadFromFile("C:\\Users\\acer\\Desktop\\document.png")) {
        std::cout<<"Failed to load t2"<<std::endl;
    }
    sf::Texture t3;
    while (!t3.loadFromFile("C:\\Users\\acer\\Desktop\\document.png")) {
        std::cout<<"Failed to load t3"<<std::endl;
    }

    sf::Sprite spr1;
    sf::Sprite spr2;
    sf::Sprite spr3;
    spr1.setTexture(t1);
    spr2.setTexture(t2);
    spr3.setTexture(t3);

    spr1.setPosition(0, 100);
    spr2.setPosition(0, 200);
    spr3.setPosition(0, 300);

    sf::RenderWindow w1(sf::VideoMode(800, 600), "test");
    while (true) {
        w1.clear();
        w1.draw(spr1);
        w1.draw(spr2);
        w1.draw(spr3);
        w1.display();
    }

    std::cout<<"SUCCESS"<<std::endl;

    return 0;
}
 

As you can see, t1, t2 and t3 are all loading the same file from an absolute path. However, t2 "fails quietly". t1 loads the right texture and displays. t3 loads the right texture and displays. t2 loads a blank texture and displays.. Nothing.

Also, in my slightly more complex code that I'm using, I used absolute paths to test it, loads a blank =/ And it's *also* the 2nd texture. I guess I could get around it by loading a blank texture twice after an OFD opens to ensure textures loaded after that run fine..

Hmm..

It would also appear that you were right about the OFD messing my directory up. Any idea how to get around that?

7
Graphics / Re: Blocking main thread causes failed texture load
« on: July 18, 2013, 04:51:40 am »
Okay, so here's another test I did to see just how long I'd have to wait before being able to load textures again:
#include<SFML/Window.hpp>
#include<SFML/Graphics.hpp>
#include<Windows.h>
#include<string>
#include<iostream>
int main () {
    sf::RenderWindow window(sf::VideoMode(800, 600), "test");
    OPENFILENAME opendialog = {0};
    WCHAR szFile[260] = {0};

    opendialog.lStructSize = sizeof (opendialog);
    opendialog.hwndOwner = window.getSystemHandle();
    opendialog.hInstance = GetModuleHandle(NULL);
    opendialog.lpstrFile = &szFile[0];
    opendialog.nFilterIndex = 0;
    opendialog.nMaxFile = 256;
    opendialog.lpstrInitialDir = NULL;
    opendialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    //This call blocks the main thread; blocking causes texture loading to fail
    GetOpenFileName(&opendialog);

    sf::Texture t1;
    while (!t1.loadFromFile("sfml-logo-small.png")) {
        std::cout<<"Failed to load t1"<<std::endl;
    }
    std::cout<<"SUCCESS"<<std::endl;

    return 0;
}
 

And..
It never ever succeeds. Ever.
I get the error: "Failed to load image "sfml-logo-small.png". Reason: Unable to open file".. Forever.

It just loops on and on.

---
And another test; passing in NULL to hwndOwner and without a window.
#include<SFML/Window.hpp>
#include<SFML/Graphics.hpp>
#include<Windows.h>
#include<string>
#include<iostream>
int main () {
    OPENFILENAME opendialog = {0};
    WCHAR szFile[260] = {0};

    opendialog.lStructSize = sizeof (opendialog);
    opendialog.hwndOwner = NULL;
    opendialog.hInstance = GetModuleHandle(NULL);
    opendialog.lpstrFile = &szFile[0];
    opendialog.nFilterIndex = 0;
    opendialog.nMaxFile = 256;
    opendialog.lpstrInitialDir = NULL;
    opendialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    //This call blocks the main thread; blocking causes texture loading to fail
    GetOpenFileName(&opendialog);
   
    sf::Texture t1;
    while (!t1.loadFromFile("sfml-logo-small.png")) {
        std::cout<<"Failed to load t1"<<std::endl;
    }
    std::cout<<"SUCCESS"<<std::endl;

    return 0;
}
 

Also, just loops an error forever.


Without GetOpenFileName(), it works on the first attempt, outputs "SUCCESS" and closes.

8
Graphics / Re: Blocking main thread causes failed texture load
« on: July 16, 2013, 04:23:59 pm »
Intel(R) HD Graphics 3000

9
Graphics / Re: Blocking main thread causes failed texture load
« on: July 16, 2013, 03:31:09 pm »
Yeah, I considered leaving out the location and other stuff but was too lazy =P
I use VS2012 and I'm using SFML2.0's "Visual C++ 11 (2012) - 32 bits" version from this page: http://sfml-dev.org/download/sfml/2.0/

10
Graphics / Re: Blocking main thread causes failed texture load
« on: July 16, 2013, 03:15:36 pm »
That's strange =/
It breaks on my laptop, though.

OS Name   Microsoft Windows 7 Home Premium
Version   6.1.7601 Service Pack 1 Build 7601
Other OS Description    Not Available
OS Manufacturer   Microsoft Corporation
System Name   ACER-PC
System Manufacturer   Acer
System Model   Aspire 4750
System Type   x64-based PC
Processor   Intel(R) Core(TM) i7-2630QM CPU @ 2.00GHz, 2001 Mhz, 4 Core(s), 8 Logical Processor(s)
BIOS Version/Date   Phoenix Technologies Ltd. V1.23, 28/4/2011
SMBIOS Version   2.6
Windows Directory   C:\Windows
System Directory   C:\Windows\system32
Boot Device   \Device\HarddiskVolume2
Locale   Singapore
Hardware Abstraction Layer   Version = "6.1.7601.17514"
User Name   acer-PC\acer
Time Zone   Malay Peninsula Standard Time
Installed Physical Memory (RAM)   4.00 GB
Total Physical Memory   3.85 GB
Available Physical Memory   970 MB
Total Virtual Memory   8.24 GB
Available Virtual Memory   2.30 GB
Page File Space   4.38 GB
Page File   C:\pagefile.sys

11
Graphics / Re: Blocking main thread causes failed texture load
« on: July 16, 2013, 09:55:59 am »
Exactly what I said, blocking the main thread =/
GetOpenFileName() blocks the main thread and shows an open file dialog until it is closed.
This blocking causes texture loading to fail where it would, otherwise, succeed.

After reducing it to the following simple example, it fails and outputs an error message on the first texture for me. But in the more complex code I have, it's the second texture that fails quietly (or, rather, loads a blank texture).

But I think the underlying problem's the same in both cases. Blocking the main thread just before calling loadFromFile() will cause it to bug when it would, otherwise, succeed.

#include<SFML/Window.hpp>
#include<SFML/Graphics.hpp>
#include<Windows.h>
#include<string>
#include<iostream>
int main () {
    sf::RenderWindow window(sf::VideoMode(800, 600), "test");
    OPENFILENAME opendialog = {0};
    WCHAR szFile[260] = {0};

    opendialog.lStructSize = sizeof (opendialog);
    opendialog.hwndOwner = window.getSystemHandle();
    opendialog.hInstance = GetModuleHandle(NULL);
    opendialog.lpstrFile = &szFile[0];
    opendialog.nFilterIndex = 0;
    opendialog.nMaxFile = 256;
    opendialog.lpstrInitialDir = NULL;
    opendialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    //This call blocks the main thread; blocking causes texture loading to fail
    GetOpenFileName(&opendialog);

    sf::Texture t1;
    sf::Texture t2;
    sf::Texture t3;

    if (!t1.loadFromFile("sfml-logo-small.png")) {
        std::cout<<"Failed to load t1"<<std::endl;
        return 0;
    }
    if (!t2.loadFromFile("sfml-logo-small.png")) {
        std::cout<<"Failed to load t2"<<std::endl;
        return 0;
    }
    if (!t3.loadFromFile("sfml-logo-small.png")) {
        std::cout<<"Failed to load t3"<<std::endl;
        return 0;
    }
   
    sf::Sprite s1;
    sf::Sprite s2;
    sf::Sprite s3;

    s1.setTexture(t1);
    s2.setTexture(t2);
    s3.setTexture(t3);

    s1.setPosition(0, 0);
    s2.setPosition(0, 100);
    s3.setPosition(0, 200);

    while (true) {
        window.clear();
        window.draw(s1);
        window.draw(s2);
        window.draw(s3);
        window.display();
    }

    return 0;
}
 

12
Graphics / Blocking main thread causes failed texture load
« on: July 16, 2013, 04:55:05 am »
I was testing some stuff and got this to work:
01) Open File Dialog opens (using some old deprecated C++ code..)
02) File is selected
03) Texture A is loaded from a file (not related to open file dialog)
04) Texture B is loaded from a file (not related to open file dialog)
05) Texture C is loaded from a file (not related to open file dialog)

The problem is, the A and C load and render fine. But B fails to load and no error message is output onto the console. It just fails quietly.. And even reports that the texture is loaded.
As in, the error here never triggers but the texture loaded is just.. Blank:
if (!texture.loadFromFile("filename")) {
    //error
}
 

Also notice that none of the textures loaded are related to the file chosen in the OFD. When I remove the code for the OFD so the main thread is never blocked, all three textures load and render without issues.

It's only when I block the thread that the 2nd texture fails to load.. Which is weird. I would think that it should be the first texture that fails, if any of the three has to fail.

The deprecated C++ code I'm talking about is:
    OPENFILENAME opendialog = {0};
    WCHAR szFile[260] = {0};

    opendialog.lStructSize = sizeof (opendialog);
    opendialog.hwndOwner = hwnd;
    opendialog.hInstance = GetModuleHandle(NULL);
    opendialog.lpstrFile = &szFile[0];
    opendialog.nFilterIndex = 0;
    opendialog.nMaxFile = 256;
    opendialog.lpstrInitialDir = NULL;
    opendialog.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

    GetOpenFileName(&opendialog);
    return std::wstring(szFile);
 

13
General / Efficient and easy collision detection?
« on: April 03, 2012, 08:16:01 am »
Hi, I've been working on a little game framework as a learning experience but have hit a brick wall.
My game is tile-based and will have agents moving about.

I've gotten agent-to-tile collision working with a constant time complexity (yay) which means moving n-agents, I only have to do n-work to check if their new positions will collide with a tile; cool.

However, agent-to-agent collision is much harder for me =/
I've been thinking of solutions but have been hard pressed to come up with any.

If I do a naive implementation (as I have done), I'll end up with (n-1) comparisons for moving one agent and [n(n-1)]/2 comparisons for moving n-agents. That is, check each agent and see if they collide; if they don't, allow them to move.

I've thought of a bunch of ways; like having them in a list sorted by x-coordinates at all times so that the checks I have to do is significantly less. But then, I run into the problem of having to update the list as I move the units and swapping things around. Even thought of splitting the game-world that the agents live into grids of 5 tiles but that doesn't solve my book-keeping problem.

I just can't really wrap my head around an efficient algorithm. My agents are always 32.32 pixels in size (so that's one thing that's made slightly easier.)

Are there any hints on how I could store my agents that always have their locations changing?

14
General / Just a few questions about sf::Sprite
« on: January 18, 2012, 08:28:16 pm »
Got it, thanks for the quick response, guys =)

15
General / Just a few questions about sf::Sprite
« on: January 18, 2012, 06:40:59 pm »
I noticed (only recently) that I could do something like this:
Code: [Select]

Create sprite
Set sprite's texture

Draw sprite to screen
Change sprite's position
Draw sprite to screen

Display


And it'll make two images appear at different locations.
I had been using one sf::Sprite per image before that =x

Anyways, which of the following is better for drawing multiple images to the screen at different positions?
A) One texture, many sprites with that texture.
B) One texture, one sprite with that texture but has its position moved around and drawn to the screen.

I'm guessing it's option B but I'd rather ask and be sure.

Also, if I had many different textures..
Should I be doing this?
Many textures, one sprite.

For each image, I just set the one sprite's texture, set the sprite's position and draw it.

So the loop will be, like:
Code: [Select]

sf::Sprite 'A' was created some where..
for each image I want to draw
    set A's texture to that image
    set A's position
    draw A
end

render_window.Display()

Pages: [1] 2