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

Pages: [1] 2
1
Graphics / How to set texture for vertices array
« on: March 15, 2012, 11:39:50 pm »
Ok. i manage somehow to make solution for vs2010 and compiled debug & release libs of SMFL. Now to replace all function names to lowercase   :cry:

2
Graphics / How to set texture for vertices array
« on: March 15, 2012, 11:11:18 pm »
Quote

For example, to generate a Visual Studio 10 solution, you must choose "Visual Studio 10". To generate makefiles usable with Visual C++, select "NMake makefiles".


What is a difference beetwen vs2010 and Visual c++ in this context?
Now i don't know what to choose?
What is NMake makefiles JOM?

3
Graphics / How to set texture for vertices array
« on: March 15, 2012, 10:54:01 pm »
Why don't you release prebuilt binaries?
Why do everybody likes this stupid CMake? Its junk generator!

Oh god why are you tortuering me??? O why did you make my life harder?

I dont understand this from tutorial (I am using VS2010):
Quote

With Visual C++, you can either run CMake from the "Visual Studio command prompt" available from the start menu, or call the vcvars32.bat file of your Visual Studio installation; it will setup the environment variables properly.

> your_visual_studio_folder\VC\bin\vcvars32.bat
> cmake


Do i need both of these programs? Whats with this combination?

What to choose here for VS2010 c++

a vs 2010 or NMake makefiles?

4
Graphics / How to set texture for vertices array
« on: March 15, 2012, 08:58:39 pm »
Ok. Here is a test src:
Code: [Select]

#include <iostream>
#include <SFML/Graphics.hpp>

#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")

int main()
{
try
{
sf::RenderWindow wnd(sf::VideoMode( 200, 200, 32 ), "Test vertices");

sf::Texture tex;
if(!tex.LoadFromFile("smoke.tga"))
{
throw std::runtime_error("Failed to load texture!");
}

float tw = (float)tex.GetWidth();
float th = (float)tex.GetHeight();

sf::Transform transform;
transform.Translate(100.0f, 100.0f);
sf::RenderStates rs;
rs.Transform = transform;
rs.Texture   = &tex;
rs.BlendMode = sf::BlendNone;

float size = 50.0f;
sf::Vertex vertices[6];
vertices[0].Color        = sf::Color(255,255,255,255);
vertices[0].Position.x   = size;
vertices[0].Position.y   = size;
vertices[0].TexCoords    = sf::Vector2f(tw, th);

vertices[1].Color        = sf::Color(255,255,255,255);
vertices[1].Position.x   = size;
vertices[1].Position.y   = -size;
vertices[1].TexCoords    = sf::Vector2f(tw, 0.0f);

vertices[2].Color        = sf::Color(255,255,255,255);
vertices[2].Position.x   = -size;
vertices[2].Position.y   = -size;
vertices[2].TexCoords    = sf::Vector2f(0.0f, 0.0f);

vertices[3].Color        = sf::Color(255,255,255,255);
vertices[3].Position.x   = size;
vertices[3].Position.y   = size;
vertices[3].TexCoords    = sf::Vector2f(tw, th);

vertices[4].Color        = sf::Color(255,255,255,255);
vertices[4].Position.x   = -size;
vertices[4].Position.y   = -size;
vertices[4].TexCoords    = sf::Vector2f(0.0f, 0.0f);

vertices[5].Color        = sf::Color(255,255,255,255);
vertices[5].Position.x   = -size;
vertices[5].Position.y   = size;
vertices[5].TexCoords    = sf::Vector2f(0.0f, th);


while(wnd.IsOpen())
{
sf::Event event;
while( wnd.PollEvent(event) )
{
switch(event.Type)
{
case sf::Event::Closed:
{
wnd.Close();
return false;
}break;
};
}
wnd.Clear(sf::Color(0, 0, 0));

wnd.Draw( vertices, 6, sf::Triangles, rs);

wnd.Display();
}
}
catch( const std::runtime_error& e)
{
std::cout << e.what() << std::endl;
std::cin.ignore();
return EXIT_FAILURE;
}
std::cin.ignore();
return EXIT_SUCCESS;
}


render screenshot:


tga image in Photoshop (saved as 32bits uncompressed). i have recolored "borders" to be blue for easier explaination:


Image uploaded to sendspace:
http://www.sendspace.com/file/zqgnlg

I expected render (with BlendNone) to show blue "borders" aroun green circle.

I expected this with BlendNone (edit in Photoshop):

5
Graphics / How to set texture for vertices array
« on: March 15, 2012, 07:07:55 pm »
Thats it hanks.

But its strange that i have specified BlendNone yet it shows no white "borders" aroung green circle? Whats wrong?

6
Graphics / How to set texture for vertices array
« on: March 15, 2012, 06:32:09 pm »
Hmmm. I can't get this right. if image has alpha channel nothing is displayed, and if it does not then it only shows vertex color:

Code: [Select]

int main() {
...
sf::Texture tex;
if(!tex.LoadFromFile("smoke.tga"))
{
return 1;
}

sf::RenderStates rs;
rs.Texture = &tex;
rs.BlendMode = sf::BlendNone;

float size = 50.0f;
sf::Vector2f pos(400.0f, 300.0f);
sf::Vertex vertices[6];
vertices[0].Color        = sf::Color(255,255,255,255);
vertices[0].Position.x   = pos.x + size;
vertices[0].Position.y   = pos.y + size;
vertices[0].TexCoords    = sf::Vector2f(1.0f, 1.0f);

vertices[1].Color        = sf::Color(255,255,255,255);
vertices[1].Position.x   = pos.x + size;
vertices[1].Position.y   = pos.y - size;
vertices[1].TexCoords    = sf::Vector2f(1.0f, 0.0f);

vertices[2].Color        = sf::Color(255,255,255,255);
vertices[2].Position.x   = pos.x - size;
vertices[2].Position.y   = pos.y - size;
vertices[2].TexCoords    = sf::Vector2f(0.0f, 0.0f);

vertices[3].Color        = sf::Color(255,255,255,255);
vertices[3].Position.x   = pos.x + size;
vertices[3].Position.y   = pos.y + size;
vertices[3].TexCoords    = sf::Vector2f(1.0f, 1.0f);

vertices[4].Color        = sf::Color(255,255,255,255);
vertices[4].Position.x   = pos.x - size;
vertices[4].Position.y   = pos.y - size;
vertices[4].TexCoords    = sf::Vector2f(0.0f, 0.0f);

vertices[5].Color        = sf::Color(255,255,255,255);
vertices[5].Position.x   = pos.x - size;
vertices[5].Position.y   = pos.y + size;
vertices[5].TexCoords    = sf::Vector2f(0.0f, 1.0f);
...
wnd.Draw( vertices, 6, sf::Triangles, rs);


here is a image "smoke.tga"(32bits, uncompressed tga):
http://fs10u.sendspace.com/processupload.html

Is just a green circle with

7
Graphics / How to set texture for vertices array
« on: March 15, 2012, 12:44:22 pm »
Thanks.

8
Graphics / How to set texture for vertices array
« on: March 15, 2012, 12:32:44 pm »
I tried to search but could not find what i need.
How to set texture for vertices array:
Code: [Select]

sf::Vertex* vert = new sf::Vertex[6];
...//fill vertices
...
??? SetTexture(???) ; // WHAT?
window.Draw( vert, 6, sf::Triangles);


Thanks for your time.

9
General discussions / SFML Box2D another example
« on: March 05, 2012, 12:45:40 am »
Hi, sorry for intrusion on this topic.
I have some problem with Box2D and SMFL, especialy circle shapes, i made a minimalistic code that shows problem:
VS2010
Box2D 2.21
SMFL 2.0

Code: [Select]

#include <iostream>

// SMFL
#include <SFML/Graphics.hpp>
#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")

// Box2D
#include <Box2D/Box2D.h>
#pragma comment(lib, "Box2D.lib")

#define B2_PIXEL_RATIO 30.0f

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Vector2f winSize = window.GetDefaultView().GetSize();

sf::Vector2f shapePosition(winSize.x * 0.5f, winSize.y * 0.5f);

// Rect body
float radius = 20.0f;
sf::CircleShape  rcShape(radius);
rcShape.SetPosition(shapePosition);
rcShape.SetFillColor(sf::Color(255,255,0,255));

b2World  phWorld(b2Vec2(0, 0));

b2BodyDef shapeBodyDef;
shapeBodyDef.type     = b2_dynamicBody;
shapeBodyDef.position = b2Vec2(shapePosition.x / B2_PIXEL_RATIO, shapePosition.y / B2_PIXEL_RATIO);
b2Body* shapeBody     = phWorld.CreateBody(&shapeBodyDef);

b2CircleShape circleShape;
circleShape.m_radius = radius / B2_PIXEL_RATIO;

b2FixtureDef rcShapeFixDef;
rcShapeFixDef.shape       = &circleShape;
rcShapeFixDef.density     = 10.0f;
rcShapeFixDef.friction    = 0.4f;
rcShapeFixDef.restitution = 1.0f;
shapeBody->CreateFixture(&rcShapeFixDef);

// Surround screen with static edges
b2FixtureDef groundBoxDef;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
b2Body* groundBody = phWorld.CreateBody(&groundBodyDef);

b2Vec2 vs[5];
vs[0].Set(winSize.x / B2_PIXEL_RATIO, 0.0f);
vs[1].Set(winSize.x / B2_PIXEL_RATIO, winSize.y / B2_PIXEL_RATIO);
vs[2].Set(0.0f, winSize.y / B2_PIXEL_RATIO);
vs[3].Set(0.0f, 0.0f);
vs[4].Set(winSize.x / B2_PIXEL_RATIO, 0.0f);
b2ChainShape wallShape;
wallShape.CreateChain(vs, 5);
groundBoxDef.shape = &wallShape;
groundBody->CreateFixture(&groundBoxDef);

float scale = 5.0f;
shapeBody->SetLinearVelocity(b2Vec2(scale, scale));

while(window.IsOpen())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}

float timeStep = 1.0f / 6000.0f;
phWorld.Step(timeStep, 10, 10);

float x = shapeBody->GetPosition().x * B2_PIXEL_RATIO;
float y = shapeBody->GetPosition().y * B2_PIXEL_RATIO;
rcShape.SetPosition(x, y);

window.Clear();
window.Draw(rcShape);
window.Display();
}
return EXIT_SUCCESS;
}



When i run this circle has some offset and penetrates bottom & right part of the screen and also for left & top can't reach all the way.
Sorry for my english, can't explain any better, and i am really frustrated as i can't find out whats wrong.
If you find time, please help.

10
Graphics / SetOrigin on shapes
« on: March 04, 2012, 09:18:33 pm »
I guess it is top-left as you said. I thought it would be same as center of mass (witch is by default centre of shape).  :oops:
Even better, no need for SetOrigin then.

11
Graphics / SetOrigin on shapes
« on: March 04, 2012, 07:18:55 pm »
For some reason i get some offset when drawing shapes:

yellow is the shape, red are debug draw.


I made smallest example for you to try:
VS2010
Box2D 2.2.1
SMFL 2.0
Code: [Select]

#include <iostream>

// SMFL
#include <SFML/Graphics.hpp>
#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")

// Box2D
#include <Box2D/Box2D.h>
#pragma comment(lib, "Box2D.lib")

#define B2_PIXEL_RATIO 30.0f

class MyDebugDraw : public b2Draw
{
private:
sf::RenderWindow* wnd;
public:
MyDebugDraw(sf::RenderWindow* w) : wnd(w) {}
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{}
void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
sf::Vertex* vert = new sf::Vertex[vertexCount];
for(int32 i = 0; i < vertexCount; ++i)
{
vert[i].Position.x = vertices[i].x * B2_PIXEL_RATIO;
vert[i].Position.y = vertices[i].y * B2_PIXEL_RATIO;
vert[i].Color.r    = 255;
vert[i].Color.g    = 0;
vert[i].Color.b    = 0;
vert[i].Color.a    = 255;
vert[i].TexCoords.x = 0.0f;
vert[i].TexCoords.y = 0.0f;
}
wnd->Draw(vert, vertexCount, sf::Lines);
delete [] vert;
}
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
{}
void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color)
{}
void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
{
}
void DrawTransform(const b2Transform& xf)
{}
};

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Vector2f winSize = window.GetDefaultView().GetSize();

sf::Vector2f shapeSize(100.0f, 30.0f);
sf::Vector2f shapePosition(winSize.x * 0.5f, winSize.y * 0.5f);

// Rect body
sf::RectangleShape rcShape;
rcShape.SetSize(shapeSize);
rcShape.SetOrigin(shapeSize * 0.5f);
rcShape.SetPosition(shapePosition);
rcShape.SetFillColor(sf::Color(255,255,0,255));

b2World  phWorld(b2Vec2(0.0f, 0.98f));
MyDebugDraw debugDraw(&window);
phWorld.SetDebugDraw(&debugDraw);
debugDraw.SetFlags(b2Draw::e_shapeBit);

b2BodyDef shapeBodyDef;
shapeBodyDef.type     = b2_dynamicBody;
shapeBodyDef.position = b2Vec2(shapePosition.x / B2_PIXEL_RATIO, shapePosition.y / B2_PIXEL_RATIO);
b2Body* shapeBody     = phWorld.CreateBody(&shapeBodyDef);

b2Vec2 vertices[4];
vertices[0].Set(0.0f, 0.0f);
vertices[1].Set(shapeSize.x / B2_PIXEL_RATIO, 0.0f);
vertices[2].Set(shapeSize.x / B2_PIXEL_RATIO, shapeSize.y / B2_PIXEL_RATIO);
vertices[3].Set(0.0f, shapeSize.y / B2_PIXEL_RATIO);
int32 count = 4;

b2PolygonShape rcPolyShape;
rcPolyShape.Set(vertices, 4);

b2FixtureDef rcShapeFixDef;
rcShapeFixDef.shape       = &rcPolyShape;
rcShapeFixDef.density     = 20.0f;
rcShapeFixDef.friction    = 0.4f;
rcShapeFixDef.restitution = 0.1f;
shapeBody->CreateFixture(&rcShapeFixDef);

// Surround screen with static edges
b2FixtureDef groundBoxDef;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0,0);
b2Body* groundBody = phWorld.CreateBody(&groundBodyDef);

b2Vec2 vs[5];
vs[0].Set(winSize.x / B2_PIXEL_RATIO, 0.0f);
vs[1].Set(winSize.x / B2_PIXEL_RATIO, winSize.y / B2_PIXEL_RATIO);
vs[2].Set(0.0f, winSize.y / B2_PIXEL_RATIO);
vs[3].Set(0.0f, 0.0f);
vs[4].Set(winSize.x / B2_PIXEL_RATIO, 0.0f);
b2ChainShape wallShape;
wallShape.CreateChain(vs, 5);
groundBoxDef.shape = &wallShape;
groundBody->CreateFixture(&groundBoxDef);

static sf::Clock clock;
while(window.IsOpen())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}

float timeStep = (float)clock.GetElapsedTime().AsMilliseconds() / 1000.0f;
phWorld.Step(timeStep, 10, 10);

float x = shapeBody->GetPosition().x * B2_PIXEL_RATIO;
float y = shapeBody->GetPosition().y * B2_PIXEL_RATIO;
rcShape.SetPosition(x, y);

window.Clear();
window.Draw(rcShape);
phWorld.DrawDebugData();
window.Display();
}
return EXIT_SUCCESS;
}



I can't see whats wrong.

Thanks for your time.

12
Graphics / SetOrigin on shapes
« on: March 04, 2012, 06:21:27 pm »
Suppose i have rectangle shape with size 100x30 and i use SetOrigin 50 , 15, does calling SetPosition moves shape based on Origin or top left corner of rectangle shape (0,0) ?

I have some weird offsets when draw debug data with Box2D.

Thanks for your time.

13
Graphics / Draw line
« on: March 03, 2012, 02:09:31 pm »
To use same thread for another stupid question.  :oops:

How can i setup view so that +Y axis is going from down-up, and X axis to stay same?

14
Graphics / Draw line
« on: March 03, 2012, 01:46:38 pm »
Found it!!!  :D

Thanks for your help, pointing into right search keywords.

http://www.sfml-dev.org/forum/viewtopic.php?p=42814&highlight=rectangleshape#42814

15
Graphics / Draw line
« on: March 03, 2012, 01:11:41 pm »
I am sorry, but i used search before posting my question and could not find nothing with "draw line" keywords.

I tried this but nothing displayed:

Code: [Select]

#include <iostream>

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>

#pragma comment(lib, "sfml-graphics-d.lib")
#pragma comment(lib, "sfml-window-d.lib")
#pragma comment(lib, "sfml-system-d.lib")
#pragma comment(lib, "sfml-audio-d.lib")

class Line : public sf::Shape
{
private:
sf::Vector2f pt[4];
public:
Line(const sf::Vector2f& pt1, const sf::Vector2f& pt2, float thick = 1.0f)
{
pt[0] = pt1 - sf::Vector2f((thick / 2.0f), (thick / 2.0f));
pt[1] = pt1 + sf::Vector2f((thick / 2.0f), (thick / 2.0f));
pt[2] = pt2 + sf::Vector2f((thick / 2.0f), (thick / 2.0f));
pt[3] = pt2 - sf::Vector2f((thick / 2.0f), (thick / 2.0f));
SetFillColor(sf::Color(255, 255, 255, 255));
}

unsigned int GetPointCount() const
{
return 4;
}

sf::Vector2f GetPoint(unsigned int index) const
{
return pt[index];
}
};


int main()
{
try
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

Line line = Line(sf::Vector2f(0.0f, 0.0f), sf::Vector2f(50.0f, 50.0f), 4.0f);

while (window.IsOpen())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}

window.Clear();

window.Draw(line);

window.Display();
}
}
catch(const std::runtime_error& e)
{
std::cerr << e.what() << std::endl;
}

    return 0;
}



I am  really sorry but i am new to SMFL and C++.

Thanks for your time.

EDIT: Please, if you find time to point me to some of the topics about lines, i still can't find one.

Also, i have trouble to build quad given two points to simulate line, how should i calculate corner points?

And, in what order (CW or CCW) these points to be created?

Thanks in advance for your patience.

Pages: [1] 2
anything