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

Pages: [1]
1
Graphics / [solved] FFMPEG problem
« on: July 17, 2009, 08:53:26 pm »
Problem solved, sorry for the inconvenience, I hope it'll help others who have the same problem.

Solution :
* Forget about the warning.
* Go to the locations of the errors :
- Replace "codec.codec_type" by "codec->codec_type". Codec is a pointer.
- Replace "pCodecCtx=&pFormatCtx->..." by "pCodecCtx=pFormatCtx->..."
* Use function prototypes in the top of your code.
* Add this function :

Code: [Select]
int img_convert(AVPicture* dst, PixelFormat dst_pix_fmt, AVPicture* src, PixelFormat pix_fmt, int width, int height)
{
   int av_log = av_log_get_level();
   av_log_set_level(AV_LOG_QUIET);
   SwsContext *img_convert_ctx = sws_getContext(width, height, pix_fmt, width, height, dst_pix_fmt, SWS_BICUBIC, NULL, NULL, NULL);
   int result = sws_scale(img_convert_ctx, src->data, src->linesize, 0, height, dst->data, dst->linesize);
   sws_freeContext(img_convert_ctx);
   av_log_set_level(av_log);
   return result;
}

2
Graphics / [solved] FFMPEG problem
« on: July 17, 2009, 08:38:17 pm »
Hello.

I'm trying to play a video file with the Graphics component of SFML, so I used this French tutorial : http://www.sfml-dev.org/wiki/fr/tutoriels/integrervideo.

Here is my code (directly copied from the tutorial) :

Code: [Select]
#include <SFML/Graphics.hpp>
extern "C"
{
  #include <libavformat/avformat.h>
  #include <libavcodec/avcodec.h>
}

sf::RenderWindow App;
sf::Image im_video;
sf::Sprite sp_video;
sf::Uint8 *Data;

AVFormatContext *pFormatCtx;
int             videoStream;
int             iFrameSize;
AVCodecContext  *pCodecCtx;
AVFrame         *pFrame;
AVFrame         *pFrameRGB;
uint8_t         *buffer;
AVPacket        packet;

int init_video(char* filename);
void display();
void close_video();


int init_video(char* filename)
{

AVCodec   *pCodec;

av_register_all();
 
  if(av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0)
  {
    fprintf(stderr, "Unexisting file!\n");
    return -1;
  }
 
  if(av_find_stream_info(pFormatCtx)<0)
  {
    fprintf(stderr, "Couldn't find stream information!\n");
    return -1;
  }
 
  dump_format(pFormatCtx, 0, filename, 0);

  videoStream=-1;
  for(int i=0; i<(pFormatCtx->nb_streams); i++)
  {
    if(pFormatCtx->streams[i]->codec.codec_type==CODEC_TYPE_VIDEO)
    {
      videoStream=i;
      break;
    }
  }
  if(videoStream==-1)
    return -1;
 
  pCodecCtx=&pFormatCtx->streams[videoStream]->codec;

  pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
  if(pCodec==NULL)
  {
    fprintf(stderr, "Unsupported codec!\n");
    return -1;
  }
 
  if(avcodec_open(pCodecCtx, pCodec)<0)
    return -1;
  iFrameSize = pCodecCtx->width * pCodecCtx->height * 3;

  pFrame=avcodec_alloc_frame();
 
  pFrameRGB=avcodec_alloc_frame();
  if(pFrameRGB==NULL)
    return -1;

  int numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
  buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
 
  avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
                pCodecCtx->width, pCodecCtx->height);

  Data = new sf::Uint8[pCodecCtx->width * pCodecCtx->height * 4];
 
  return 0;
}

void display()
{
  int frameFinished;
 
  if (av_read_packet(pFormatCtx, &packet) < 0)
  {
    close_video();
    //exit(0);
  }
 
  if(packet.stream_index==videoStream)
  {
avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
                        packet.data, packet.size);
 
    if(frameFinished)
    {
      // Convert the image from its native format to RGB
      img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
                  (AVPicture*)pFrame, pCodecCtx->pix_fmt, pCodecCtx->width,
                  pCodecCtx->height);
 }

int j = 0;
    for(int i = 0 ; i < (iFrameSize) ; i+=3)
    {
      Data[j] = pFrameRGB->data[0][i];
      Data[j+1] = pFrameRGB->data[0][i+1];
      Data[j+2] = pFrameRGB->data[0][i+2];
      Data[j+3] = 255;
      j+=4;
    }
    im_video.LoadFromPixels(pCodecCtx->width, pCodecCtx->height, Data);

}
  // Dessiner l'image sur le tampon de l'écran
  App.Draw(sp_video);
}

void close_video()
{
  // Libérer le packet alloué par av_read_frame
  av_free_packet(&packet);
  // Libérer l'image RGB
  av_free(buffer);
  av_free(pFrameRGB);
  // Libérer l'image YUV
  av_free(pFrame);
  // Fermer le codec
  avcodec_close(pCodecCtx);
  // Fermer le  fichier video
  av_close_input_file(pFormatCtx);
}

int main()
{
// Notre fonction pour initialiser la video
if ( init_video("test.avi") == 0 )
{
 // Code SFML de base
 App.Create( sf::VideoMode(pCodecCtx->width*2, pCodecCtx->height*2, 32),
                             "Video avec SFML et FFMpeg"
                           );
 
// On crée notre image, en blanc par exemple
 im_video.Create(pCodecCtx->width, pCodecCtx->height, sf::Color(255,255,255,255));
// J'aime bien ne pas mettre le smooth, ça dépend de la qualité de la video :)
 im_video.SetSmooth(false);
// On crée notre sprite
 sp_video.SetImage(im_video);
// Vous pouvez utiliser les fonctionnalité du sprite sur la video,
// comme le scale, de la même manière qu'une simple image fixe
 
 // La boucle principale
 bool Running = true;
 while (Running)
 {
   // Les évènements
   sf::Event Event;
   while (App.GetEvent(Event))
   {
     if (Event.Type == sf::Event::Closed)
       Running = false;
 
     if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
       Running = false;
   }
 
// Notre fonction de lecture et dessin de la video
   display();
 
// On affiche tout ça
   App.Display();
   App.SetFramerateLimit(50);
 }
 
// Notre fonction pour fermer la video
 close_video();
 return EXIT_SUCCESS;
}
  return EXIT_FAILURE;
}



I've also correctly added the following libraries : avformat.lib and avcodec.lib. When I'm trying to build, I get this error :


Code: [Select]
1>------ Build started: Project: ffmpeg_test1, Configuration: Release Win32 ------
1>Compiling...
1>main.cpp
1>.\main.cpp(49) : warning C4018: '<' : signed/unsigned mismatch
1>.\main.cpp(51) : error C2228: left of '.codec_type' must have class/struct/union
1>        type is 'AVCodecContext *'
1>        did you intend to use '->' instead?
1>.\main.cpp(60) : error C2440: '=' : cannot convert from 'AVCodecContext **' to 'AVCodecContext *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\main.cpp(108) : error C3861: 'img_convert': identifier not found
1>Build log was saved at "file://c:\Projects\vcpp\ffmpeg_test1\ffmpeg_test1\Release\BuildLog.htm"
1>ffmpeg_test1 - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Can anyone please help me there ?

3
Graphics / Avoiding the sf::String bug with an array
« on: July 17, 2009, 07:38:40 pm »
I've solved my particular problem of text not drawing itself. It was a pretty stupid error in fact, my "default.ttf" file wasn't located in the "res/img" folder, but in "res/ttf" one...

Well, thanks a lot for your time, and talking about SFML 2.0, I'll wait for the official release builds. I've a very bad experience with building my sources alone (endless days and nights trying to solve never ending building errors, and never once I got a thing correctly compiled...) So thank you very much for your hint, but I think I'll just be patient ! ^^

4
Graphics / Avoiding the sf::String bug with an array
« on: July 17, 2009, 12:50:08 pm »
No, I use the 1.5, since no other releases are available.

I gave the whole code because I don't know where my problem comes from. The text objects don't throw any errors, but they're not visible on my window App...

5
Graphics / Avoiding the sf::String bug with an array
« on: July 16, 2009, 07:30:42 pm »
Thanks a lot for your answers, but my problem remains.
When I use the code you gave, dunce, everything compiles neatly whithout any error or warning, but when I launch the application, the texts don't show up.

I'll give you my C++ codes (some comments are in french, sorry about that). Here is my main.cpp :


Code: [Select]
//main.cpp


// Les Includes de SFML
#include <iostream>

// L'Include de Snake
#include "Game.h"


// La fonction principale du programe
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
//int main(int argc, char **argv)
//int main()
{
Game SnSt2Game;

SnSt2Game.init();

SnSt2Game.loop();

std::cout << "Loop ended !" << std::cout;

    return EXIT_SUCCESS;
}



Code: [Select]
//Game.h

// Defines
#define MAX_GAMEMODES 50

// Protection contre les inclusions multiples
#ifndef GAME_H
#define GAME_H

#include <iostream>
#include <fstream>
#include <SFML/Graphics.hpp>
#include "GameMode.h"



class Game
{

public:

// Méthodes
Game();
~Game();
void init();
void loop();

protected:

// Attributs
sf::RenderWindow window;
GameMode *gamemode[TOTALWORKINGMODES];
int active_gamemode;
};





#endif


Code: [Select]
//Game.cpp


#include "Game.h"





Game::Game() : window(sf::VideoMode::GetDesktopMode(), "SnakeSteaks 2", sf::Style::Fullscreen)
{
}


void Game::init()
{
for(int i = 0 ; i < TOTALWORKINGMODES ; i++)
{
gamemode[i] = new GameMode(window, i);
gamemode[i]->init();
}

active_gamemode = 0;
}


void Game::loop()
{
while(active_gamemode != EXITMODE)
{
std::cout << "Looping..." << std::endl;

window.Clear(sf::Color(255,255,255));

// Handle events
int new_mode = gamemode[active_gamemode]->handle_events();

if(new_mode != DEFAULTMODE && active_gamemode != EXITMODE)
{
active_gamemode = new_mode;
}

gamemode[active_gamemode]->update();

gamemode[active_gamemode]->refresh();

if(!(window.IsOpened()))active_gamemode = EXITMODE;

std::cout << "Game Mode : " << active_gamemode << std::endl;

window.Display();
}


}


Game::~Game()
{
for(int i = 0 ; i < TOTALWORKINGMODES ; i++)
{
delete gamemode[i];
}
}




Code: [Select]
//GameMode.h

// Defines
#define MAXSAMEOBJECTS 100
#define TOTALWORKINGMODES 1

#define EXITMODE -2
#define DEFAULTMODE -1
#define MENUMODE 0

#define WINDOW_X float(window.GetWidth())
#define WINDOW_Y float(window.GetHeight())
#define PERCENT_X  * float(window.GetWidth()) / 100.f
#define PERCENT_Y  * float(window.GetHeight()) / 100.f

// Protection contre les inclusions multiples
#ifndef GAMEMODE_H
#define GAMEMODE_H

#include <SFML/Graphics.hpp>
#include <iostream>
//#include "MyString.h"


class GameMode
{

public:

// Méthodes
GameMode(sf::RenderWindow &refwindow, int new_id);
void init();
int handle_events();
void handle_event(sf::Event &events);
void update();
void refresh();
~GameMode();

protected:

// Attributs
int mode_id;
int game_mode;
std::string name;
sf::Image img_fond;
sf::Sprite fond;
sf::Image image[MAXSAMEOBJECTS];
sf::Sprite sprite[MAXSAMEOBJECTS];
sf::String *texte[MAXSAMEOBJECTS];
sf::Font fonte[MAXSAMEOBJECTS];
sf::RenderWindow &window;

};





#endif




Code: [Select]
//GameMode.cpp


#include "GameMode.h"



GameMode::GameMode(sf::RenderWindow &refwindow, int new_id) : window(refwindow)
{
fonte[0].LoadFromFile("res/img/default.ttf");

for(int i = 0; i < MAXSAMEOBJECTS ; i++)
{
texte[i] = new sf::String("", fonte[0]);
}

switch(new_id)
{
case MENUMODE:
name = "Menu";
break;

default:
std::cout << "Error : Undefined mode " << new_id << std::endl;
name = "Error";
break;
}

mode_id = new_id;
}



void GameMode::init()
{

switch(mode_id)
{
case MENUMODE:
std::cout << "Initialising Menu" << std::endl;
// Loading resources
if (!img_fond.LoadFromFile("res/img/fond.jpg"))
{
std::cout << "Problem loading image." << std::endl;
}
else
{
std::cout << "Loading successful !" << std::endl;
}

// Using resources
fond.SetImage(img_fond);
fond.Resize(WINDOW_X, WINDOW_Y);
//fond.SetPosition(0.f, 0.f);

window.Draw(fond);

texte[0]->SetText("Solo");
texte[0]->SetSize(20);
texte[0]->SetColor(sf::Color::Black);
texte[0]->SetPosition((5 PERCENT_X),(10 PERCENT_Y));

texte[1]->SetText("Multi");
texte[1]->SetSize(20);
texte[1]->SetColor(sf::Color::Black);
texte[1]->SetPosition((5 PERCENT_X),(50 PERCENT_Y));
break;

default:
break;
}
}


int GameMode::handle_events()
{
game_mode = DEFAULTMODE;

sf::Event events;
    while (window.GetEvent(events) && game_mode != EXITMODE)
{
        if (events.Type == sf::Event::Closed)
game_mode = EXITMODE;

handle_event(events);
}

if(game_mode == EXITMODE)window.Close();
if(!(window.IsOpened()))game_mode = EXITMODE;

return game_mode;
}


void GameMode::handle_event(sf::Event &events)
{

switch(mode_id)
{
case MENUMODE:
if (events.Type == sf::Event::KeyPressed)
{
// Esc or Q : Quitter
if (events.Key.Code == sf::Key::Escape || events.Key.Code == sf::Key::Q)
game_mode = EXITMODE;
}
break;

default:
break;

}
}


void GameMode::update()
{

switch(mode_id)
{
case MENUMODE:
std::cout << "Nothing to update" << std::endl;
break;

default:
break;
}
}


void GameMode::refresh()
{

switch(mode_id)
{
case MENUMODE:
std::cout << "Drawing menu background..." << std::endl;

window.Draw(fond);

for(int i = 0 ; i < 2 ; i++)
{
window.Draw(*texte[i]);
}

window.Draw(*texte[0]);

break;

default:
break;
}
}



GameMode::~GameMode()
{
for(int i = 0 ; i < MAXSAMEOBJECTS ; i++)
{
delete texte[i];
}
}




Thanks a lot if you can help me !

6
Graphics / Avoiding the sf::String bug with an array
« on: July 15, 2009, 08:48:18 pm »
Hullo.

I'm using the sf::String class, and I get the known Access Violation bug.
I know it comes from the default font destructor, so I'm searching a solution to avoid this problem.

The only thing that's making trouble is that I use an array :
Code: [Select]
sf::String text[100];

The constructor of my GameClass didn't seem to like for loops, so I decided to use pointers and allocation :

Code: [Select]
// This is the pointer array
sf::String* text[100];


// Later I allocate them :
sf::Font MyDefaultFont;
MyDefaultFont.LoadFromFile("default.ttf");
for(int i = 0; i < 100 ; i++)
{
text[i] = new sf::String("", MyDefaultFont);
}


// Everyting's fine this far, I do not forget to delete in the destructor of my GameClass :
for(int i = 0; i < 100 ; i++)
{
delete text[i];
}



The problem I have, and I'm sure it's a stupid one, is with the Draw function...

When I try window.Draw(text[0]), it says that I should use a reference and not a pointer, and when I try window.Draw(*text[0]), everything works fine... except the text is not drawn at all !

(I tried many other ways, creating my own derivated MyString class, but I can't use a custom font because there is no such constructor like font("myverycoolfont.ttf") - which would be very cool by the way, so I tried to create a MyFont class, but still the font wont be loaded from a file within the constructor, etc., etc...)

7
Feature requests / Cross-platform Video solution
« on: July 15, 2009, 07:42:08 pm »
Ok, thank you very much ! I'm going to check out ffmpeg.

8
Feature requests / Cross-platform Video solution
« on: July 14, 2009, 08:34:46 pm »
Hullo !

My name is Jan Keromnes, and I'm the project manager of 7D², a french video game creation team. We're using the SFML library in some of our projects, and we find it really cool because it's cross-platform, incredibly simple, efficient, and, in short, SFML rocks !

The only thing that is really missing in SFML is a solution for videos. Programming video games without being able to play videos is a little frustrating, and I don't like the idea of using a new not-cross-platform library just to play a few videos...

I know it sounds like a terrible lot of work and trouble, but I think that SFML (which is a media library by the way) could so much more with a cross-platform video module, and I know I'm far from being the only one thinking that.

Thank you very much for what you do and for reading this !
Hoping that one day, SFML will be able to handle videos,

Jan.

Pages: [1]
anything