Partage
  • Partager sur Facebook
  • Partager sur Twitter

[SDL/OpenGL] Une petite classe

    8 octobre 2007 à 23:58:15

    Salut les zeros,

    je suis entrain d'essayer de coder une petite classe qui me permet de gérer SDL et OpenGL, c'est une petite surcouche pour ne plus avoir a taper le même code a chaque projet mais voila le compilo me sort des erreurs incompréhensibles :o

    Voila le code incriminer ( désoler mais je commente en anglais :( ):

    S_Engine.h
    1. #ifndef S_ENGINE_H
    2. #define S_ENGINE_H
    3. #include <SDL.h>
    4. #ifdef WIN32    // If we are using VCC we must include windows.h
    5.     #include <windows.h>
    6. #endif
    7. #include <GL/gl.h>
    8. #include <GL/glu.h>
    9. #include <string>
    10. #ifdef WIN32                                                                                                    // If We're Under MSVC
    11.     #pragma comment( lib, "OpenGL32.lib" )                                                      // We Can Tell The Linker To Look For OpenGl32.lib ...
    12.     #pragma comment( lib, "GLu32.lib" )                                                         // ...GLu32.lib ...
    13.     #pragma comment( lib, "SDLmain.lib" )                                                       // ...SDLmain.lib ...
    14.     #pragma comment( lib, "SDL.lib" )                                                           // And SDL.lib At Link Time
    15. #endif
    16. namespace S_Engine
    17. {
    18.     class S_Engine
    19.     {
    20.     public:
    21.         S_Engine(int Width = 640, int Height = 480, int BPP = 16, bool fullScreen = false);
    22.         ~S_Engine(void);
    23.         inline void setCaption(std::string AppName);
    24.         int exec();
    25.     private:
    26.         inline bool init();
    27.         inline bool initSDL();
    28.         inline bool initGL();
    29.         inline void showCursor(bool show);
    30.         inline void handleMessages();
    31.         inline void reshapeGL(int Width, int Height);
    32.         SDL_Surface *m_screen;
    33.         int m_width, m_height;
    34.         int m_bpp;
    35.         bool m_fullScreen;
    36.         bool m_done;
    37.         std::string m_appName;
    38.     };
    39. }
    40. #endif


    S_Engine.cpp :

    1. #include <SDL.h>
    2. #ifdef WIN32    // If we are using VCC we must include windows.h
    3.     #include <windows.h>
    4. #endif
    5. #include <GL/gl.h>
    6. #include <GL/glu.h>
    7. #include <iostream>
    8. #include "S_Engine.h"
    9. using namespace std;
    10. namespace S_Engine
    11. {
    12.     S_Engine::S_Engine(int Width, int Height, int BPP, bool fullScreen) :
    13.             m_width(Width), m_height(Height), m_bpp(BPP), m_fullScreen(fullScreen), m_done(false)
    14.     {
    15.     }
    16.     S_Engine::~S_Engine(void)
    17.     {
    18.     }
    19.     bool S_Engine::init()
    20.     {
    21.         initSDL();
    22.         initGL();
    23.         reshapeGL(m_width,m_height);
    24.         return true;
    25.     }
    26.     void S_Engine::reshapeGL(int Width, int Height)
    27.     {
    28.         glViewport(0,0,(GLsizei)(Width),(GLsizei)(Height));                                             // Reset The Current Viewport
    29.         glMatrixMode(GL_PROJECTION);                                                                                    // Select The Projection Matrix
    30.         glLoadIdentity();                                                                                                               // Reset The Projection Matrix */
    31.         gluPerspective(45.0f,(GLfloat)(Width)/(GLfloat)(Height),1.0f,100.0f);   // Calculate The Aspect Ratio Of The Window
    32.         glMatrixMode(GL_MODELVIEW);                                                                                             // Select The Modelview Matrix
    33.         glLoadIdentity();                                                                                                               // Reset The Modelview Matrix
    34.     }
    35.     bool S_Engine::initGL()
    36.     {
    37.         glEnable(GL_TEXTURE_2D);
    38.         glClearColor(0.0f,0.0f, 0.0f,0.0f);             // Color Background
    39.         glClearDepth(1.0f);                                                                                     // Depth Buffer Setup
    40.         glDepthFunc(GL_LEQUAL);                                                                         // The Type Of Depth Testing (Less Or Equal)
    41.         glEnable(GL_DEPTH_TEST);                                                                        // Enable Depth Testing
    42.         glShadeModel(GL_SMOOTH);                                                                        // Select Smooth Shading
    43.         glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    44.         glColor4f(1.0f, 1.0f, 1.0f, 0.5f);                                                      // Gestion de la transarence
    45.         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    46.         return true;
    47.     }
    48.     void S_Engine::setCaption(string AppName)
    49.     {
    50.         SDL_WM_SetCaption(AppName.c_str(), NULL);                                                                               // We're Setting The Window Caption
    51.     }
    52.     bool S_Engine::initSDL()
    53.     {
    54.         if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
    55.         {
    56.             cout << "Could not initialize SDL" << endl;
    57.             cout << "Error : " << SDL_GetError() << endl;
    58.             return false;
    59.         }
    60.         atexit(SDL_Quit);
    61.         const SDL_VideoInfo *infoHardware = SDL_GetVideoInfo();
    62.         if ( !infoHardware )
    63.         {
    64.             cout << "Could not retrive video info" << endl;
    65.             cout << "Error : " << SDL_GetError() << endl;
    66.         }
    67.         Uint32 videoFlags;
    68.         videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    69.         videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
    70.         videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
    71.         videoFlags |= SDL_OPENGLBLIT;           /* To be able to blit 2d image on screen */
    72.         if ( !m_fullScreen )
    73.             videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */
    74.         else
    75.             videoFlags |= SDL_FULLSCREEN;
    76.         /* This checks to see if surfaces can be stored in memory */
    77.         if ( infoHardware->hw_available && infoHardware)
    78.             videoFlags |= SDL_HWSURFACE;
    79.         else
    80.             videoFlags |= SDL_SWSURFACE;
    81.         /* This checks if hardware blits can be done */
    82.         if ( infoHardware->blit_hw && infoHardware )
    83.             videoFlags |= SDL_HWACCEL;
    84.         /* Sets up OpenGL double buffering */
    85.         SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
    86.         /* get a SDL surface */
    87.         m_screen = SDL_SetVideoMode( m_width, m_height, m_bpp,
    88.                                      videoFlags );
    89.         /* Verify there is a surface */
    90.         if ( !m_screen )
    91.         {
    92.             cout << "Could not set video mode" << endl;
    93.             cout << "Error :" << SDL_GetError() << endl;
    94.             return false;
    95.         }
    96.         SDL_FillRect(m_screen, NULL, SDL_MapRGBA(m_screen->format,0,0,0,0));
    97.         return true;
    98.     }
    99.     void S_Engine::showCursor(bool show)
    100.     {
    101.         SDL_ShowCursor( show ? 1 : 0);
    102.     }
    103.     void S_Engine::handleMessages()
    104.     {
    105.         SDL_Event event;
    106.         // Gestion des messages recus
    107.         while ( SDL_PollEvent( &event ) )
    108.         {
    109.             switch ( event.type )
    110.             {
    111.             case SDL_QUIT:
    112.                 m_done = true;
    113.                 break;
    114.             case SDL_MOUSEMOTION:
    115.                 //      Recupere la position de la souris
    116.                 break;
    117.                 // Quand on 'déclique'
    118.             case SDL_MOUSEBUTTONUP:
    119.                 switch ( event.button.button )
    120.                 {
    121.                 case SDL_BUTTON_LEFT:
    122.                 case SDL_BUTTON_MIDDLE:
    123.                 case SDL_BUTTON_RIGHT:
    124.                 default:
    125.                     break;
    126.                 }
    127.                 break;
    128.                 // Clics de la souris
    129.             case SDL_MOUSEBUTTONDOWN:
    130.                 switch ( event.button.button )
    131.                 {
    132.                     // Boutons
    133.                 case  SDL_BUTTON_LEFT:
    134.                 case  SDL_BUTTON_MIDDLE:
    135.                 case  SDL_BUTTON_RIGHT:
    136.                     break;
    137.                 default:
    138.                     break;
    139.                 }
    140.                 break;
    141.             case SDL_KEYDOWN:
    142.                 //       event.key.keysym.sym  = la touche pressee;
    143.                 break;
    144.             case SDL_KEYUP:
    145.                 break;
    146.             default:
    147.                 break;
    148.             }
    149.         }
    150.     }
    151.     int S_Engine::exec()
    152.     {
    153.         if ( !init() )
    154.         {
    155.             cout << "Errot while initiliazing SDL" << endl;
    156.             return 1;
    157.         }
    158.         while ( !m_done )
    159.         {
    160.             handleMessages();
    161.             //double buffering -> echange le back buffer
    162.             SDL_GL_SwapBuffers();
    163.             glClear(GL_COLOR_BUFFER_BIT);
    164.         }
    165.         return 0;
    166.     }
    167. }


    main.cpp :

    1. #include <iostream>
    2. #include "S_Engine.h"
    3. int main()
    4. {
    5.     S_Engine test;
    6.     test.setCaption("Hello Sly Engine");
    7.         return test.exec();
    8. }


    et l'erreur en question :

    C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)(.text+0x397):: In function `console_main':
    \Users\hercules\trunk\SDL-1.2\.\src\main\win32\SDL_win32_main.c:217: undefined reference to `SDL_main'
    :: === Build finished: 1 errors, 4 warnings ===


    P.S: j'ai envie de coder cette classe pour qu'elle soit multiplatformes , et multi-compilo :-°
    P.S 2 : il n'y a pas de probleme de linkage j'ai verifier.
    P.S 3 :p : Je n,ai mis que l'erreur de gcc(Code::Blocks), celle de Visual est une autre erreur.
    • Partager sur Facebook
    • Partager sur Twitter
      9 octobre 2007 à 2:42:38

      Avec SDL, il est obligatoire de donner les arguments au main:
      tranforme
      1. int main()
      en
      1. int main(int arc, char *argv[])
      • Partager sur Facebook
      • Partager sur Twitter
        9 octobre 2007 à 12:54:23

        Oui c'est vrai est en plus je le savait, en tous cas merci

        Eh ben non, l'erreur est toujours la mais maintenant je vais mettre celle de Visual.

        1>------ Début de la génération : Projet : SlyEngine, Configuration : Debug Win32 ------
        1>Édition des liens en cours...
        1>S_Engine.obj : warning LNK4075: ' /EDITANDCONTINUE' ignoré à cause de la spécification '/OPT:ICF'
        1>LINK : fatal error LNK1561: le point d'entrée doit être défini
        1>SlyEngine - 1 erreur(s), 1 avertissement(s)
        ========== Génération : 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========
        • Partager sur Facebook
        • Partager sur Twitter

        [SDL/OpenGL] Une petite classe

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown