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

Pages: [1] 2 3
1
DotNet / [SFML2] Using Shaders
« on: January 30, 2011, 03:04:05 pm »
Another question related to shaders, how would I set the value of an item within an array in the shader?

For example, if I have:
Code: [Select]
uniform vec2 points[16];

How would I change values in "points" with SFML?

2
DotNet / [SFML2] Using Shaders
« on: January 29, 2011, 06:35:46 pm »
It may have just been something wrong with the contents then.

Anyway, I got a Shader working through the FromString method. Thanks for your help, and thanks for SFML! :D

3
DotNet / [SFML2] Using Shaders
« on: January 29, 2011, 05:54:29 pm »
Thank you for the quick reply!

The file is in the bin\Debug and bin\Release folders with the executable, and is copied there from the project directory on compile (therefore it is in both).

Does the previously mentioned exception occur if the file is found but the contents are bad?

And thanks for changing FromString to be static, I will probably use that instead of from a file.

4
DotNet / [SFML2] Using Shaders
« on: January 29, 2011, 04:20:57 pm »
How would I create a shader instance from a file / from a string in SFML.NET 2.0?

I've tried:
Code: [Select]
TestShader = new Shader( "Shader.sfx" );
But I get a LoadingFailedException. The file definitely exists at the specified location.

Shader.sfx is just an example shader:
Code: [Select]
uniform sampler2D tex;

void main()
{
   gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
}


Loading from a string would be more suitable for my needs, but the LoadFromString() method requires an instance of Shader. I would have expected it to be a static method.

5
Graphics / [SFML 2] Crashing at random time
« on: February 09, 2010, 10:56:37 pm »
I made a copy constructor (my first), and it works! I think I understand why, because it didn't allocate memory for the sf::Image in the entity.

I think I know when I'll need a copy constructor and destructor now, when I have members in the function that can take up varying amounts of memory (like an array).

Thanks again, I have learnt something new :D

Edit: I still get memory access violations after about 2 minutes :( I'll post my constructor / copy constructor / where I add to the vector like you said anyway.

Code: [Select]
// Constructor
Bug::Bug( unsigned int s, unsigned int b, unsigned int g, sf::Vector2f p )
{
if( s < 1 )
s = 1;
if( s > 180 )
s = 180;

if( b < 1 )
b = 1;
if( b > 180 )
b = 180;

if( g < 1 )
g = 1;
if( g > 180 )
g = 180;

info.shell = s;
info.body  = b;
info.gut   = g;

health = pref_start_health;
food = 0;

pos = p;
vel = sf::Vector2f( sf::Randomizer::Random( -( int )pref_speed_max, pref_speed_max ) * 1.f, sf::Randomizer::Random( -( int )pref_speed_max, pref_speed_max ) * 1.f );

sf::Image tm_image;
my_image.Create( 16, 16, sf::Color( 0, 0, 0, 0 ));

tm_image.Create( 16, 16, sf::Color( 0, 0, 0, 0 ));

tm_image.Copy( img_shell, 0, 0, sf::IntRect( 0, 0, 16, 16 ),  true );
ShadeImage   ( tm_image,  GetPartShade( info.shell ));
my_image.Copy( tm_image,  0, 0, sf::IntRect( 0, 0, 16, 16 ), true );

tm_image.Create( 16, 16, sf::Color( 0, 0, 0, 0 ));

tm_image.Copy( img_body,  0, 0, sf::IntRect( 0, 0, 16, 16 ), true );
ShadeImage   ( tm_image,  GetPartShade( info.body  ));
my_image.Copy( tm_image,  0, 0, sf::IntRect( 0, 0, 16, 16 ), true );

tm_image.Create( 16, 16, sf::Color( 0, 0, 0, 0 ));

tm_image.Copy( img_gut,   0, 0, sf::IntRect( 0, 0, 16, 16 ), true );
ShadeImage   ( tm_image,  GetPartShade( info.gut   ));
my_image.Copy( tm_image,  0, 0, sf::IntRect( 0, 0, 16, 16 ), true );

my_sprite.SetImage( my_image );
my_sprite.SetPosition( pos.x - 8, pos.y - 8 );

alive = true;
age = 0.f;

last_acid = 0.f;
id = next_id ++;
}


Code: [Select]
// Copy Constructor
Bug::Bug( const Bug &bug )
{
info.shell = bug.info.shell;
info.body  = bug.info.body;
info.gut   = bug.info.gut;

health = bug.health;
food = bug.food;

pos = bug.pos;
vel = bug.vel;

my_image = bug.my_image;
my_sprite.SetImage( my_image );

my_sprite.SetPosition( pos.x - 8, pos.y - 8 );

alive = bug.alive;
age = bug.age;

last_acid = bug.last_acid;
id = bug.id;
}


Code: [Select]
// Adding to vector (This is a static function)
void Bug::AddBug( unsigned int s, unsigned int b, unsigned int g, sf::Vector2f p )
{
if( !images_loaded )
{
images_loaded = true;
img_shell.LoadFromFile( "shell.png" );
img_body.LoadFromFile( "body.png" );
img_gut.LoadFromFile( "gut.png" );

img_acid.LoadFromFile( "acid.png" );
img_food.LoadFromFile( "food.png" );
}
bug_list.push_back( Bug( s, b, g, p )); // bug_list is the vector
}


Code: [Select]
// Removing from vector
std::vector<Bug>::iterator b_i = Bug::bug_list.begin();
while( b_i != Bug::bug_list.end())
{
if( !b_i->Think( inc, app_window ))
b_i = Bug::bug_list.erase( b_i );
else
++ b_i;
}


"Bug::Think" returns true if the bug entity is still active, or false if it should be removed.

6
Graphics / [SFML 2] Crashing at random time
« on: February 09, 2010, 10:33:14 pm »
Quote from: "Nexus"
Quote from: "Metapyziks"
But new problem: I have a vector containing the entities which have a sprite each, which is constantly being added to and entities are removed every so often too.
Can you post the definition of the entity class and the code where you insert/remove elements into/from the container?

Maybe your class doesn't support full value semantics, which is required for STL containers. Could you show the implementation of the entity class's copy constructor, copy assignment operator and destructor, too, if you have defined these functions yourself?


*Goes and writes a copy constructor / assignment operator / destructor*

 :roll: I am quite new to C++ anyway. I'll tell you if adding them fixes it.

7
Graphics / [SFML 2] Crashing at random time
« on: February 09, 2010, 08:32:17 pm »
Quote from: "Nexus"
If I download a new SVN version, I will always recompile the whole SFML project solution and the dependent projects. This saves me from tedious errors. ;)

At least I know now :D

But new problem: I have a vector containing the entities which have a sprite each, which is constantly being added to and entities are removed every so often too.

The problem is that the images set to the sprite of each entity seems to stick based on position in the vector, because when a new entity is removed from the vector some of the entities change their sprite.

It's hard to describe, so I'll upload an example:
http://www.robertandsherman.co.uk/downloads/BugThingExample.zip

This is just a guess at what is causing them to change image. They should all stay the same after they are created.

I can fix this by using Sprite.SetImage() every time the sprite is drawn, but I doubt that is the best method.

8
Graphics / [SFML 2] Crashing at random time
« on: February 09, 2010, 08:08:16 pm »
Quote from: "panithadrum"
Hmm My little experience about dll's tells me that if I update SFML from SVN and don't compile the dll's (and put it to my project) it will crash at any moment, so try to compile the dlls and make sure your project loads them.


Thanks, that sounds likely since I haven't updated the dlls in a while.

9
Graphics / [SFML 2] Crashing at random time
« on: February 09, 2010, 07:32:34 pm »
I have a load of small sprites (16*16, >64 of them) drawn onto my window each frame. After about one or two minutes, the app crashes with an access violation error:


The variable I use to work out how much the sprites should move (I use the time since they were last drawn) looks like this in the debugger:
Code: [Select]
4.316e-039#DEN

Could this be part of the problem?

Edit: It crashes on a line where I pass the variable mentioned to a function.

10
Graphics / [Resolved][SFML2] OpenGL Drawing texture
« on: January 14, 2010, 10:26:08 pm »
Ok, I think I know the problem now. I needed to set the texture coordinates for each quad.

Thanks for your help!

11
Graphics / [Resolved][SFML2] OpenGL Drawing texture
« on: January 14, 2010, 10:18:37 pm »
Quote from: "Laurent"
Well, you can start with the OpenGL sample from the SDK. It creates an OpenGL texture from the image, but you can comment out this part and use the image and its Bind() function directly. It should be faster than writing an example from scratch :)


Well I just finished one anyway, with the problem in the OP:
Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
sf::RenderWindow app_window;
app_window.Create( sf::VideoMode( 768, 512 ), "Texture Test", sf::Style::Close );

sf::Image image;
image.LoadFromFile( "test.png" );

sf::Sprite sprite( image );

glClearDepth( 1.f );
glClearColor( 0.f, 0.f, 0.f, 0.f );

glEnable( GL_DEPTH_TEST );
glDepthMask( GL_TRUE );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 90.f, 1.f, 1.f, 500.f );

while( app_window.IsOpened())
{
sf::Event this_event;
while( app_window.GetEvent( this_event ))
{
switch( this_event.Type )
{
case sf::Event::Closed:
app_window.Close();
}
}

app_window.Clear();

/* Checking to see if the image has loaded fine */
app_window.Draw( sprite );

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.f, 0.f, -200.f );

/* De-comment the next line, and the cube is not drawn for me */
//image.Bind();

glBegin( GL_QUADS );

glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f,  50.f, -50.f);
glVertex3f( 50.f,  50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);

glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f,  50.f, 50.f);
glVertex3f( 50.f,  50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);

glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f,  50.f, -50.f);
glVertex3f(-50.f,  50.f,  50.f);
glVertex3f(-50.f, -50.f,  50.f);

glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f,  50.f, -50.f);
glVertex3f(50.f,  50.f,  50.f);
glVertex3f(50.f, -50.f,  50.f);

glVertex3f(-50.f, -50.f,  50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f,  50.f);

glVertex3f(-50.f, 50.f,  50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f,  50.f);

glEnd();

app_window.Display();
}
}


But I'll try to use the method in the example now, like you said.

12
Graphics / [Resolved][SFML2] OpenGL Drawing texture
« on: January 14, 2010, 10:01:22 pm »
Quote from: "Laurent"
Indeed, in SFML 2 you don't have to do anything. Can you provide a minimal and complete piece of code that reproduces the problem?


I've got a lot of it strewn over several classes, but I'll try to make a simple app that does this.

13
Graphics / [Resolved][SFML2] OpenGL Drawing texture
« on: January 14, 2010, 09:51:11 pm »
Quote from: "Laurent"
Did you call window.PreserveOpenGLStates(true) ?


It's not a member of sf::RenderWindow or sf::Window, probably because I am using SFML 2. What is the equivalent in SFML 2, if that is the problem?

Edit: Changed the OP title

14
Graphics / [Resolved][SFML2] OpenGL Drawing texture
« on: January 14, 2010, 09:42:16 pm »
I have a sf::Image that I want to use as the faces of the standard example cube. What steps should I take in order to use it? I made a guess with this:
Code: [Select]
...

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

image.Bind();

glBegin(GL_QUADS);

glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f,  50.f, -50.f);
glVertex3f( 50.f,  50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);

glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f,  50.f, 50.f);
glVertex3f( 50.f,  50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);

glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f,  50.f, -50.f);
glVertex3f(-50.f,  50.f,  50.f);
glVertex3f(-50.f, -50.f,  50.f);

glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f,  50.f, -50.f);
glVertex3f(50.f,  50.f,  50.f);
glVertex3f(50.f, -50.f,  50.f);

glVertex3f(-50.f, -50.f,  50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f,  50.f);

glVertex3f(-50.f, 50.f,  50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f,  50.f);

glEnd();

...


Where "image" exists, and by simply commenting out the image.Bind() line the cube draws (although white), so the OpenGL part works.

What should I do?

15
Graphics / [SFML 2] Using opengl
« on: December 31, 2009, 11:56:33 pm »
(I'm using VC++ 2008 express)

I'm trying to use opengl in a project, but I keep getting errors similar to this:
Code: [Select]
1>.\main.cpp(23) : error C3861: 'glClearDepth': identifier not found
1>.\main.cpp(24) : error C3861: 'glClearColor': identifier not found
1>.\main.cpp(27) : error C2065: 'GL_DEPTH_TEST' : undeclared identifier
....


There are many more like that, one for each opengl related thing I reference.

I tested it with the opengl example from your tutorials (the errors above are from that). I have included the following things as additional dependencies in the linker settings:
Code: [Select]
glu32.lib
opengl32.lib
sfml-main.lib
sfml-system.lib
sfml-window.lib
sfml-graphics.lib


What could the problem be?

Pages: [1] 2 3