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

Pages: [1] 2 3
1
General / Opengl 3 + SFML 2 + Mac OS X Mountain Lion
« on: December 14, 2012, 08:14:24 am »
I'm having some difficulties with this program. It compiles fine and everything and no OpenGL error is thrown during execution but what I see is just a black window (see clear color). How's that? (Here's Utility.hpp and Utility.cpp)

On a side note. Mac OS X Mountain Lion supports almost every procedure of OpenGL 3.2 but the card is listed as OpenGL 2.1 card. But as you can see I can use all the function of OpenGL 3.2 without having any "undefined identifier" error. Maybe SFML creates an OpenGL 2 context?

Fragment shader
#version 120

varying vec4 pass_Color;
void main(void) {
        gl_FragColor = pass_Color;
}

Vertex shader
#version 120

uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
attribute vec4 in_Color;
attribute vec4 in_Position;
varying vec4 pass_Color;
void main(void) {
        gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position;
        pass_Color = in_Color;
}

2
General / Re: How to link OpenGL on Mac OS X and Netbeans?
« on: August 01, 2012, 01:44:18 pm »
Thanks. Does this also works for GLU?

3
General / How to link OpenGL on Mac OS X and Netbeans?
« on: August 01, 2012, 12:11:39 pm »
I've read the tutorial about using OpenGL in SFML. I've added the library via #include<SFML/OpenGL.hpp>.
Then it says I have to link it in my project. So in the linker I've added -lGL -lGLU as described in tutorials online on how to link opengl. But I get an error "library not found for -lGL".

So how do I link correctly OpenGL?

4
Graphics / Re: Please help me understanding views
« on: July 30, 2012, 05:44:32 am »
Now I'm beginning to understand. But for example, if I set a sprite:

sprite.setPosition(window.convertCoords( sf::Mouse::getPosition( window ), movableView ));

and then I do:

anotherSprite.setPosition(sprite.getPosition()); // sprite that is in the movable view

I should get two sprites in the same position right?

5
Graphics / Re: Please help me understanding views
« on: July 29, 2012, 03:49:33 pm »
What? Could you provide a pseudo-code please?  :-X

6
Graphics / Re: Please help me understanding views
« on: July 29, 2012, 03:32:13 pm »
I'm really confused. I mean, when I set setPosition I'm setting the x and y offset from the View we set when we draw the sprite. Now getPosition() will return the same value right? Then If I have a fixed view (that doesn't move) with a sprite (which is linked to the mouse movement) and a movable view with other sprite and I want to move a sprite from the movable view towards the sprite in the fixed view I should do convertCoords(<position sprite from fixed view >, <movable view>). Is that correct?

7
Graphics / Re: Please help me understanding views
« on: July 29, 2012, 03:15:03 pm »
How can I covert them? convertCoords accept an integer 2d vector while the position is usually dealt with a float 2d vector. All I ask is an example, please...

8
Graphics / Please help me understanding views
« on: July 29, 2012, 02:39:09 pm »
I can't understand how views works. I've read all the tutorial on the internet of the first 2 pages of google searching for it. I've also read a view tutorial that someone posted in another question of mine. Particularly I can't get how the coordinates works when a view is there. And when there are multiple views?

When we set setPosition() of a generic object (say sf::Sprite for example) what are we setting? Are we dealing with the renderwindow x and y, the view x and y or something else? Is there a way to find out how to convert from a type of coordinates to another? What is the function convertCoords supposed to convert?

The documentation and tutorials on this website are really poor about that. Could you please explain that to me referring to SFML 2.0 specifically?

Thanks in advance.

9
Why, since all the coordinates are made in sf::Vector2f, does convertCoords() accept sf::Vector2i?

10
General / Sprite to face mouse position
« on: July 28, 2012, 11:34:27 am »
I know, I know, on the internet there are a lot of tutorial on how to get the angle between the center of two objects.
Now I have this code:

//  (180 / PI = 57.3065)
float AngleBetweenVectors(sf::Vector2f, sf::Vector2f);
float AngleBetweenVectors(sf::Vector2f a, sf::Vector2f b){
   return 57.3065f * atan2(b.y - a.y, b.x - a.x);
}
 

that get the angle, and then this code that I use to calculate it:

    float angle = AngleBetweenVectors(player_p, cursor.getPosition());
    player.setRotation(angle);
 

where player_p is the player center position (a 50x50 square sprite) and cursor is the cursor sprite I use.
player is finally the player sprite.

But when I run it it gets this kind of problems (please watch the entire video):
http://www.youtube.com/watch?v=qaS151xUPeg&feature=youtu.be

As you can see on the border of the terrain it gets a little bit tricky. Why is that? I'm using two views like that:

    window.clear(sf::Color(0, 0, 0, 255));
    window.setView(camera); // camera view
    // start drawing
        terrain.draw(); // terrain blocks
        window.draw(player); // player sprite
        window.setView(cursor_camera); // cursor view
            window.draw(cursor); // cursor sprite (the circular one)
    // end drawing logic
    window.display();
    window.setMouseCursorVisible(false); // no mouse pointer please
 

11
General / Re: Mouse position problem
« on: July 28, 2012, 03:37:04 am »
This worked fine thanks. Now we have just another problem:

The cursor sprite starts 150px on top of the cursor and when moving the cursor it's alway 150 px on the top. Why is that?
This is the code before the main loop:
Code: [Select]
    camera = window.getDefaultView();
    camera.setCenter(terrain.getCenter());
    camera.setSize(screen_width, screen_height);

    int cursor_width = 100;
    int cursor_height = 100;
    cursor_texture.loadFromFile("cursor.png");
    cursor.setTexture(cursor_texture);
    cursor.setTextureRect(sf::IntRect(0, 0, cursor_width, cursor_height));

then here I set the cursor (which is the circular sprite) like this:

Code: [Select]
cursor.setPosition(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);

12
General / Re: Mouse position problem
« on: July 28, 2012, 12:14:55 am »
Yeah, sorry. So this is my draw routine (it is called every time in the main game loop):

    window.clear(sf::Color(0, 0, 0, 255));
    window.draw(cursor);
    window.setView(camera);
    // start drawing
        terrain.draw();
        window.draw(player);
    // end drawing logic
    window.display();
 

where cursor is the sprite of the cursor
camera is the sf::View() (a very normal sf view, no special settings, it just follows the player around)
and player is our player sprite.

What I basically want to accomplish is replacing the mouse default icon with something else. Right now that code makes the cursor follow the mouse but when the camera moves it's left behind.

Also If I set the cursor sprite to be:

cursor.setPosition(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y);

I get 150px on top of the actual cursor position.

13
General / Re: Mouse position problem
« on: July 27, 2012, 11:22:37 pm »
But I'm not asking for a fix, I'm asking how to attach the mouse sprite to the screen view...

14
General / Re: Mouse position problem
« on: July 27, 2012, 02:27:24 pm »
Yeah, I thought about that too, but I was wondering if there was an easier and cleaner way.

15
General / Re: Mouse position problem
« on: July 27, 2012, 11:15:39 am »
My code is exactly the same as you posted, except for the fact that there's some more code that moves the camera when the player moves.

Pages: [1] 2 3
anything