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

Pages: [1]
1
Window / RenderWindow reference problems
« on: January 18, 2013, 07:29:48 am »
I am trying to pass a reference of the applications render window to my image handling class. As you can see
i'm using a const which should not make a copy. However I get this error from gcc.

In file included from /usr/include/SFML/Window.hpp:37:0,
                 from globals.h:28,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/System/NonCopyable.hpp: In member function ‘sf::Window& sf::Window::operator=(const sf::Window&)’:
/usr/include/SFML/System/NonCopyable.hpp:64:18: error: ‘sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)’ is private
/usr/include/SFML/Window/Window.hpp:55:16: error: within this context
In file included from /usr/include/SFML/Window.hpp:35:0,
                 from globals.h:28,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/System/NonCopyable.hpp: In member function ‘sf::Input& sf::Input::operator=(const sf::Input&)’:
/usr/include/SFML/System/NonCopyable.hpp:64:18: error: ‘sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)’ is private
/usr/include/SFML/Window/Input.hpp:44:16: error: within this context
In file included from /usr/include/SFML/Window.hpp:37:0,
                 from globals.h:28,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/Window/Window.hpp: In member function ‘sf::Window& sf::Window::operator=(const sf::Window&)’:
/usr/include/SFML/Window/Window.hpp:55:16: note: synthesized method ‘sf::Input& sf::Input::operator=(const sf::Input&)’ first required here
In file included from /usr/include/SFML/Graphics.hpp:38:0,
                 from globals.h:29,
                 from ImageHandling.h:1,
                 from ImageHandling.cpp:1:
/usr/include/SFML/Graphics/RenderWindow.hpp: In member function ‘sf::RenderWindow& sf::RenderWindow::operator=(const sf::RenderWindow&)’:
/usr/include/SFML/Graphics/RenderWindow.hpp:46:16: note: synthesized method ‘sf::Window& sf::Window::operator=(const sf::Window&)’ first required here
ImageHandling.cpp: In member function ‘void imageHandler::setScreen(const sf::RenderWindow&)’:
ImageHandling.cpp:15:16: note: synthesized method ‘sf::RenderWindow& sf::RenderWindow::operator=(const sf::RenderWindow&)’ first required here
make: *** [ImageHandling.o] Error 1

My code is as follows.

RenderWindow screen;

void imageHandler::setScreen(RenderWindow& screens) {
      screen = screens;
}
void imageHandler::surfApp( int x, int y, string imageName )
{
   map<string, Sprite>::iterator p = spriteList.find( imageName );
   if( p != spriteList.end() )
   {
       p -> second.SetPosition( x, y );
       screen.Draw( p -> second );
   }
}
 

 

2
C / Re: applying sprite to sfRenderWindow using a reference in c++
« on: January 10, 2013, 06:40:21 am »
Laurent and Nexus you both make great points. My intention was not to create a flame war here, just to point out the justifications of my personal programming decisions. As you can see from my code I am wrapping the
C style code into easy to use C++ classes. I may consider using RAII in the classes that will be deriving from
these ones. You are right my C code will be more error prone, slower, and probably be less readable. The reason for that is that i'm not an expert and don't claim to be only that i'm learning through this method. C++ as am sure you are aware is a superset of C and the great features we enjoy in C++ have to be implemented in lower levels. C++ code is also translated into ASM which is then compiled into hex instructions. Therefore C++ is
just an abstraction of tried and true opcode coding algorithms brought to us by those before us. I'm sorry if I offended any of you and look forward to working and disscussing further issues with all of you.

3
C / Re: applying sprite to sfRenderWindow using a reference in c++
« on: January 09, 2013, 02:19:40 pm »
Laurent, thank you for pointing out the code=cpp tag. I will use it it from now on. Yes, CSFML and SFML appear to be the same but you as as an SFML dev putting it so eloquently "It forces you to manage memory manually, work with pointers, use ugly structures and functions because of the lack of polymorphism and overload, etc."
. The same things more or less were said about switching and combining ASM to and from C. I am looking for
control as well as a learning experience in my ventures. As far as pointers, functions, memory, and structures
go we as software engineers use these every day and need to learn to use them properly. Or we run the the risk
of creating vulnerabilities and kinks in general. Major rewrite? Typing out long scope names of classes as opposed to just typing functions suits me just fine. As to what eXpl0it3r said "Why would use SFML's C binding and try to program in C++?" this is not advice but rather a sarcastic question. Enough of my rant, back to my programming.

4
C / Re: applying sprite to sfRenderWindow using a reference in c++
« on: January 09, 2013, 02:40:03 am »
Nevermind I figured it out I was clearing the screen before applying the sprite and using sfSprite_Move() instead of sfSprite_SetPosition() thanks anyway.  :D

5
C / Re: applying sprite to sfRenderWindow using a reference in c++
« on: January 09, 2013, 02:14:14 am »
I find the C binding less confusing to use for one. Two this is a port of an engine I made for SDL and didn't want
amjor rewrite. Constructive feedback instead of knocking my binding choice would be nice.

6
C / applying sprite to sfRenderWindow using a reference in c++
« on: January 09, 2013, 01:19:59 am »
I have a class that uses a reference to sfRenderWindow to render a sprite from a map container. The code compiles and runs fine but won't show the sprite. My code is as follows.

class imageHandler : public Unpacker
{
 
    map<string, sfImage*> imageList;
    map<string, sfSprite*> spriteList;
    public:
    sfRenderWindow* screen;
    imageHandler();
    ~imageHandler();
    void setScreen(sfRenderWindow*& screens);
    void addImage( string imageName );
    void setAlpha( string name, int alpha );
    void clearImages();
    void surfApp( int x, int y, string imageName );
    void surfApp( int X, int Y, string Name,  sfIntRect aniRect);
    int imageW( string pFilename );  
    int imageH( string pFilename );
};
 

#include "ImageHandling.h"

imageHandler::imageHandler(){
      int count = 1;
      int i;

      sfImage** imageList;
      sfSprite** spriteList;
}
imageHandler::~imageHandler(){
}
void imageHandler::setScreen(sfRenderWindow*& screens) {
      screen = screens;
}
void imageHandler::addImage( string imageName)
{
   
      sfImage* image;
      map<string, sfImage*>::iterator i = imageList.find( imageName );
      map<string, sfSprite*>::iterator p = spriteList.find( imageName );
      if( i == imageList.end() )
      {

         image = loadImageFromRes("data.pck", imageName.c_str());
         i = imageList.insert( i, make_pair( imageName, image ) );

      }
      if( p == spriteList.end() )
      {
         sfSprite* sprite = sfSprite_Create();
         sfSprite_SetImage( sprite, image );
         p = spriteList.insert(p, make_pair( imageName, sprite ) );
      }

}
void imageHandler::setAlpha( string name, int alpha )
{
    sfColor alphaAdjust;
    alphaAdjust.r = 255;
    alphaAdjust.g = 255;
    alphaAdjust.b = 255;
    alphaAdjust.a = alpha;
    map<string, sfSprite*>::iterator a = spriteList.find( name );
    if( a != spriteList.end() )
    {
        sfSprite_SetColor( a -> second, alphaAdjust );
    }
}
void imageHandler::surfApp( int x, int y, string imageName )
{
   map<string, sfSprite*>::iterator p = spriteList.find( imageName );
   if( p != spriteList.end() )
   {
       sfSprite_Move( p -> second, x, y );
       sfRenderWindow_DrawSprite( screen, p -> second );
   }
}
void imageHandler::surfApp( int X, int Y, string Name,  sfIntRect aniRect)
{
   map<string, sfSprite*>::iterator p = spriteList.find( Name );
   if( p != spriteList.end() )
   {
      sfSprite_Move(p -> second, X, Y );
      sfSprite_SetSubRect( p -> second, aniRect );
      sfRenderWindow_DrawSprite( screen, p -> second );
   }
};
int imageHandler::imageW(string pFilename)
{
      int result;
      map<string, sfImage*>::iterator p = imageList.find( pFilename );
      if( p != imageList.end() )
      {
         result = sfImage_GetWidth( p -> second );
      }
      return result;
}
int imageHandler::imageH(string pFilename)
{
    int result;
    map<string, sfImage*>::iterator p = imageList.find( pFilename );
    if( p != imageList.end() )
    {
       result = sfImage_GetHeight( p -> second );
    }
    return result;
}
 
main.cpp
#include "Engine.h"
 
int addButtonX = 40;
int addButtonY = 40;
 
sfEvent eventHolder;
 
int addAniX, addAniY = 25;
 
int dirX=1;
int dirY=4;
 
bool quit = false;
bool downupDown = true;
bool downupLeft = true;
bool downupRight = true;
 
int main(int argc, char* args[])
{
   
    imageHandler images;
    Events myEvents;
    Timer fps;
     
    images.addImage("logo.png");
     
    sfVideoMode videoParams;
    videoParams.Width = 640;
    videoParams.Height = 480;
    sfWindowSettings sfSettings;
    sfSettings.AntialiasingLevel = 0;
    sfSettings.DepthBits = 32;
    sfSettings.StencilBits = 0;
    videoParams.BitsPerPixel = 32;
    sfColor colorBlue;
    colorBlue.r = 0;
    colorBlue.g = 0;
    colorBlue.b = 255;
    sfRenderWindow* App = sfRenderWindow_Create( videoParams, "Window Test", sfTitlebar | sfClose, sfSettings  );
 
    while( sfRenderWindow_IsOpened( App ) )
    {
           fps.startTimer();
           images.setScreen(App);
           myEvents.eventStruct( eventHolder );
           while(sfRenderWindow_GetEvent( App, &eventHolder ))
           {
               if( eventHolder.Type == sfEvtClosed )
               {
                   sfRenderWindow_Close( App );
               }
               if( eventHolder.Key.Type == sfEvtKeyPressed )
               {
                   if( eventHolder.Key.Code == sfKeyNum0 )
                   {
                       cout << "Zero pressed" << endl;
                   }
                   if( eventHolder.Key.Code == sfKeyA )
                   {
                       cout << "A key pressed" << endl;
                   }
                   if( eventHolder.Key.Code == sfKeyEscape )
                   {
                      cout << "Esc key pressed" << endl;
                   }
               }
               if( myEvents.keyUp("j") == true )
               {
                   cout << "J key pressed" << endl;
               }
           }
           if( downupDown == false )
           {
              addButtonY += 10;
           }
           images.surfApp( addButtonX, addButtonY, "logo.png" );
           sfRenderWindow_Clear( App, colorBlue );
       
           sfRenderWindow_Display( App );
    }
     
    return 0;
}

Pages: [1]
anything