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

Pages: [1]
1
Thank you, that was exactly what I needed. I hadn't looked at the tutorial for several months, and was simply relying on previous experience with views and the sfml documentation. Thanks for your help.

2
Graphics / Unsure of how to find the "Pixel Position" of sf::Text. [Solved]
« on: November 30, 2015, 10:07:31 pm »
I am not going to include any code in this post as I think it is possible to explain my confusion without it, however, I will readily post some if that is what is wanted.

So, I am working on simple program which simulates planetary orbits. I am trying to add a functionality in which the user is able to click the name of an orbital object and have their view be centered on it. Moving the view is not an issue, and functions fine. The problem that I am encountering is how to correctly detect if a mouse click is positioned on the planets name text.

Psuedocode:
(click to show/hide)

This however is not enough, as it turns out that the position of the mouse and the position of the text use two separate units of measurements. The mouse position is based off of which pixel it falls on, either in relation to the upper left edge of the entire screen or based just the window depending on how you call the function. sf::text objects however, use a system of measurement related to their position in screenspace, also changing with various transformations and scaling.

How would I go about detecting if a mouse click falls within a piece of text's, (or any other drawables), bounding box? I've tried other variations and have scoured the documentation, but could not find much. sf::transform seems that it might be the path to take but I still cannot seem to solve this.

3
I have very little experience with shaders, though I doubt we will be able to know what is wrong unless you post some of your code and the vertex shader.

4
Graphics / Re: Custom button class does not display. [SOLVED]
« on: June 18, 2014, 11:21:04 pm »
I fixed it. I set the buttons origin to a position outside of the windows viewing area.

TestButton.SetButtonOrigin(200.0f, 400.0f);
 
This was out of bounds, setting the origin to (0,0) sets it in the upper left corner. Thank you Jonki and Ixrec for your help.

5
Graphics / Re: Custom button class does not display.
« on: June 16, 2014, 09:41:12 pm »
You're not supposed to have your render code inside the event loop. If there are no events, those functions won't be called.
I changed that, It doesn't really make much sense to have my display function in my event loop. I also noticed that I forgot to set ButtonText's font so I this to Buttons constructor.
ButtonText.setFont(ButtonFont);
 

I also changed:
MainWindow.draw(TestButton);
 

To:
MainWindow.draw(TestButton, sf::RenderStates::Default)
 

Since I was not sure if I needed to enter the second argument. Though the button still does not display.

6
Graphics / Re: Custom button class does not display.
« on: June 15, 2014, 11:34:29 pm »
For the rectangle: I don't see you setting the size anywhere, and the documentation says its default constructor uses a size of (0,0), so I'd try giving it a nonzero size.

For the text: You aren't checking the return value of loadFromFile(), so maybe it just can't find the font file.  If that isn't the issue, could you try drawing a simple sf::Text object (unrelated to your Button class) and make sure that shows up properly?


Thank you for the quick response, I have made the changes you suggested in my code. The button still does not display.

Main.cpp:
(click to show/hide)

GameText, a separate text from the button class, draws to the screen without any issues.

Button.h:
(click to show/hide)

Button.cpp:
(click to show/hide)

At the end of Button::draw I have a cout statement to show if the function runs correctly, my output shows the statement many times so the function is being run. I also set the rectangles initial size to 100 by 100 and it still does not get drawn. I checked the return statement of ButtonFont.loadFromFile and it returns as true. Though I think it already has a check built into itself as I have had it output that the file could not be loaded when I put in the wrong path.

For style:
- Why give the Button all of its arguments in an initialization method rather than the constructor?
- In general, passing that many arguments in one function is not a good sign.  One alternative that might be more readable would be having the constructor take a size and position, then using setFont(), setColors() and setString() methods to neatly split up all the other parameters.
- MainWindow.clear(); should be underneath the event loop, next to draw() and display().  I actually didn't see it for a while, and nearly wrote a post explaining why you need to call clear().
- Your indentation is inconsistent in a few places.
- //dtor is a completely superfluous comment

- I moved them to the constructor, that slipped my mind for some reason. I fixed it.
- I have made those changes in the code above.
- Placed it under MainWindow.display().
- When I have Code::Blocks make me a new empty class, it uses different indentation than myself and places //ctor and //dtor in the constructor and destructor. I was too lazy to clean that up, will have to at some point.  ;D

Thank you for your criticism. I will try to look for reasons for why this is still not working, but am stumped so far.

Edit: Added relevant information such as OS, SFML version, and GPU to initial post.

7
Graphics / Custom button class does not display. [SOLVED]
« on: June 15, 2014, 10:31:45 pm »
Hello, I have been teaching myself how to use SFML 2.1 for a few days and am having trouble getting a button object I made draw itself to a window. My program runs without any errors.

Main.cpp:
(click to show/hide)

Button.h:
(click to show/hide)

Button.cpp:
(click to show/hide)

Files.h:
(click to show/hide)

I made button inherit sf::drawable and made sure I did it in the same way that sf::sprite did so I could draw buttons in the same way you can draw sprites by calling window.draw(sprite). Though there are no errors when compiling and running the program, neither the buttons rectangle or it's text are drawn. I cannot figure out why though.

Thank you ahead of time for any help, and any other general tips or criticism of my code is welcome, especially if I am doing something horribly wrong.

OS: Windows 7 64bit.
SFML Version: 2.1 Static.
GPU: EVGA gtx 670 ftw.

Pages: [1]