IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

delphi et openGL


Sujet :

API, COM et SDKs Delphi

  1. #1
    Membre actif Avatar de damienlann
    Profil pro
    Étudiant
    Inscrit en
    Mai 2005
    Messages
    293
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2005
    Messages : 293
    Points : 249
    Points
    249
    Par défaut delphi et openGL
    Salut,
    Je debute sous openGl et sous delphi, mais je pense avoir compris le principe general des deux.
    Je travaille sous delphi 2006.
    J'ai déja fait des pg pour débuter qui m'affichent des formes (triangle, carré) avec des couleurs ou des dégradé, et j'aimerais passé aux textures à partir d'une image.
    J'ai fait un bout de code mais je ne vois rien et je ne sais pas d'ou ca peut venir.

    Si quelqu'un a le courage d'y regarder, je le remercie d'avance.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    var
      Form1: TForm1;
      Tex:GLuint;
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.FormCreate(Sender: TObject);
    var
        PixelFormat    :TPixelFormatDescriptor;
        cPixelFormat   :Integer;
        DoubleBuffer   :Boolean;
    begin
         DoubleBuffer := false;
         FillChar( PixelFormat, SizeOf(PixelFormat), 0 );
         With PixelFormat Do
         Begin
              nSize      := Sizeof(TPixelFormatDescriptor);
              If DoubleBuffer Then
                 dwFlags    := PFD_DOUBLEBUFFER or PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL
              Else
                  dwFlags    := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
              iLayerType := PFD_MAIN_PLANE;
              iPixelType := PFD_TYPE_RGBA;
              nVersion   := 1;
              cColorBits := 16;
              CdepthBits := 16;
         End;
         glClearColor( 0.0, 0.0, 0.0, 0.0 );
         Loadtexture(ExtractFilePath(ParamStr(0))+'texture.bmp',Tex);
    end;
    Loadtexture(ExtractFilePath(ParamStr(0))+'texture.bmp',Tex);
    fait parti d'un autre fichier que j'ai inclus.
    Je détaillerai cette fonction plus bas.
    ensuite vient l'évenement FormPaint qui permet d'afficher mon carré.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    procedure TForm1.FormPaint(Sender: TObject);
    begin
     
    Glclear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    glClearColor( 0.0, 0.0, 0.0, 0.0 );
     
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity;
     
    gluLookAt( 0.0 , 0.0 , 20.0,
               0.0 , 0.0 , 0.0,
               0.0 , 1.0 , 0.0 );
     
    glPushMatrix();
    glBindTexture( GL_TEXTURE_2D, Tex );
     
    glBegin( GL_QUADS );
    glNormal3f( 0.0, 0.0, 1.0 );
    glTexCoord2f( 01, 01 );glVertex3f( -2.0, 2.0, 0.0 );
    glTexCoord2f( 01, 0 );glVertex3f( -2.0,-2.0, 0.0 );
    glTexCoord2f( 0, 0 );glVertex3f(  2.0,-2.0, 0.0 );
    glTexCoord2f( 0, 01 );glVertex3f(  2.0, 2.0, 0.0 );
    glEnd();
    glPopMatrix();
    glFlush;
    SwapBuffers( Canvas.Handle );
     
    end;
    et enfin, l'évenement resize "basique"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    procedure TForm1.FormResize(Sender: TObject);
    begin
         {Empêcher les division par ZERO}
         If ClientHeight = 0 Then
            ClientHeight := 1;
     
         {Spécification de l'espace disponible sur le contrôle fenêtré.}
         glViewport( 0, 0, ClientWidth, ClientHeight );
         {Rendre la matrice de project active pour définir un nouveau champs de
          vision}
         glMatrixMode( GL_PROJECTION );
         glLoadIdentity();
     
         {Création d'une nouvelle matrice de projection.}
         gluPerspective( 45, ClientWidth / ClientHeight, 0.1, 500.0 );
     
         {Rafraîchir le contenu de la fenêtre}
         Form1.Invalidate;
    end;
     
    end.
    Comme promis, la fonction LoadTexture, mais je ne pense pas que le probleme vienne de là.
    Pour dire vrai, cette partie de code n'est pas de moi.
    SwapRGB permet de passer du format RGB au format GBR
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
     
    function LoadTexture(Filename: String; var Texture : GLuint) : Boolean;
    var
      FileHeader: BITMAPFILEHEADER;
      InfoHeader: BITMAPINFOHEADER;
      Palette: array of RGBQUAD;
      BitmapFile: THandle;
      BitmapLength: LongWord;
      PaletteLength: LongWord;
      ReadBytes: LongWord;
      Width, Height : Integer;
      pData : Pointer;
     
     
    begin
      result :=FALSE;
        BitmapFile := CreateFile(PChar(Filename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
        if (BitmapFile = INVALID_HANDLE_VALUE) then begin
          MessageBox(0, PChar('Error opening ' + Filename), PChar('BMP Unit'), MB_OK);
          Exit;
        end;
     
        ReadFile(BitmapFile, FileHeader, SizeOf(FileHeader), ReadBytes, nil);
        ReadFile(BitmapFile, InfoHeader, SizeOf(InfoHeader), ReadBytes, nil);
     
        PaletteLength := InfoHeader.biClrUsed;
        SetLength(Palette, PaletteLength);
        ReadFile(BitmapFile, Palette, PaletteLength, ReadBytes, nil);
        if (ReadBytes <> PaletteLength) then begin
          MessageBox(0, PChar('Error reading palette'), PChar('BMP Unit'), MB_OK);
          Exit;
        end;
     
        Width  := InfoHeader.biWidth;
        Height := InfoHeader.biHeight;
        BitmapLength := InfoHeader.biSizeImage;
        if BitmapLength = 0 then
        BitmapLength := Width * Height * InfoHeader.biBitCount Div 8;
     
        GetMem(pData, BitmapLength);
        ReadFile(BitmapFile, pData^, BitmapLength, ReadBytes, nil);
        if (ReadBytes <> BitmapLength) then begin
          MessageBox(0, PChar('Error reading bitmap data'), PChar('BMP Unit'), MB_OK);
          Exit;
        end;
        CloseHandle(BitmapFile);
     
      SwapRGB(pData, Width*Height);
     
      Texture :=CreateTexture(Width, Height, GL_RGB, pData);
      FreeMem(pData);
      result :=TRUE;
    end;
    Celui qui trouve, je lui fait un bisou....c'est promis

  2. #2
    Membre éprouvé
    Avatar de neilbgr
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2004
    Messages
    651
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2004
    Messages : 651
    Points : 1 177
    Points
    1 177
    Par défaut
    Si ton but est de comprendre/apprendre OpenGL je ne pourrais pas t'aider (dsl).
    En revanche, si ton but est d'utiliser OpenGl de façon simple et efficace, je te conseils d'installer les composants GlScene ( http://glscene.sourceforge.net ). Aussi, étant que le code est évidement fournis, tu peux regarder comment ils ont fait concernant les textures.
    "Si vous voulez être l’esclave des banques et payer pour financer votre propre esclavage, alors laissez les banquiers créer la monnaie" - Josiah Stamp, 1920, Gouverneur de la Banque d’Angleterre
    "Qui ne peut acheter ruine qui voudrait vendre" - Jacques Duboin.
    "Nous n'héritons pas la terre de nos parents, nous l'empruntons à nos enfants." - Antoine de Saint Exupéry

  3. #3
    Expert éminent
    Avatar de Lung
    Profil pro
    Analyste-programmeur
    Inscrit en
    Mai 2002
    Messages
    2 665
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 665
    Points : 6 984
    Points
    6 984
    Par défaut
    Ta question serait plus appropriée ici : http://www.developpez.net/forums/viewforum.php?f=47

    Sinon, pour ton problème, je ne vois pas le code pour charger la texture. Tu charge l'image, mais pas la texture.




    Voici ma fonction de chargement de texture (c'est pas un modèle, je suis débutant aussi. Mais, c'est pour te donner des pistes) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    procedure TFormGL.CreerTexture;
       procedure GetListeTexture(var ListeFichierTexture: TStringList);
       begin
          ListeFichierTexture.Add(MainForm.GetTemp + TEXTURE_1);
          ListeFichierTexture.Add(MainForm.GetTemp + TEXTURE_2);
          ListeFichierTexture.Add(MainForm.GetTemp + TEXTURE_3);
          ListeFichierTexture.Add(MainForm.GetTemp + TEXTURE_L);
       end;
    var
       ListeFichierTexture: TStringList;
       pTextures: PTAUX_RGBImageRec;      //.Pointeur sur une structure PTAUX_RGBImageRec stockant les pixels de l'image.
       i: Integer;      //.Variable contrôle pour créer les texture une à une.
    begin
       ListeFichierTexture := TStringList.Create;
       try
          //.Liste des fichiers de textures.
          GetListeTexture(ListeFichierTexture);
          _nNbTexture := ListeFichierTexture.Count;
     
          //.Nombre de textures.
          SetLength(_TabIDTexture, _nNbTexture);
     
          //.Génération des ID pour les textures.
          glDeleteTextures(_nNbTexture, @_TabIDTexture);
          glGenTextures(_nNbTexture, @_TabIDTexture[0]);
     
          //.Parcours de la liste des fichiers de texture.
          for i:=0 to Pred(_nNbTexture) do
          begin
             //.Chargement de la texture en mémoire.
             pTextures := auxDIBImageLoadA(PChar(ListeFichierTexture[i]));
     
             //.Si fichier chargé en mémoire.
             if Assigned(pTextures) then
             begin
                //.Chargement de la texture.
                glBindTexture(GL_TEXTURE_2D, _TabIDTexture[i]);
     
                //.Paramétrage de la texture.
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                //.Type de combinaison de la texture avec le tampon chromatique.
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                _CombinTex := cMODULATE;
     
                //.Définition de la texture 2D.
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pTextures^.SizeX, pTextures^.SizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pTextures^.Data);
                //gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pTextures^.SizeX, pTextures^.SizeY, GL_RGB, GL_UNSIGNED_BYTE, pTextures^.Data)
             end
             else
             begin
                MainForm.AddLog('[' + DateTimeToStr(Now) + '] Erreur :  le chargement de la texture ''' + ExtractFileName(ListeFichierTexture[i]) + ''' a échoué !');
                Application.MessageBox(PChar('.Erreur :  le chargement de la texture ''' + ExtractFileName(ListeFichierTexture[i]) + ''' a échoué !'), PChar(Caption + ' - erreur'), MB_ICONERROR + MB_OK);
                Exit;
             end;
          end;
       finally
          ListeFichierTexture.Free;
     
          //.Test des erreurs OpenGL.
          TestErreur('Chargement des textures');
       end;
    end;
    L'urgent est fait, l'impossible est en cours, pour les miracles prévoir un délai. ___ Écrivez dans un français correct !!

    C++Builder 5 - Delphi 6#2 Entreprise - Delphi 2007 Entreprise - Delphi 2010 Architecte - Delphi XE Entreprise - Delphi XE7 Entreprise - Delphi 10 Entreprise - Delphi 10.3.2 Entreprise - Delphi 10.4.2 Entreprise - Delphi 11.1 Entreprise
    OpenGL 2.1 - Oracle 10g - Paradox - Interbase (XE) - PostgreSQL (15.4)

  4. #4
    Membre actif Avatar de damienlann
    Profil pro
    Étudiant
    Inscrit en
    Mai 2005
    Messages
    293
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2005
    Messages : 293
    Points : 249
    Points
    249
    Par défaut
    la fonction pour charger une texture est loadtexture. (tout simplement)
    C'est la derniere partie de code que j'ai posté

  5. #5
    Expert éminent
    Avatar de Lung
    Profil pro
    Analyste-programmeur
    Inscrit en
    Mai 2002
    Messages
    2 665
    Détails du profil
    Informations personnelles :
    Âge : 44
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste-programmeur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 665
    Points : 6 984
    Points
    6 984
    Par défaut
    Citation Envoyé par damienlann
    la fonction pour charger une texture est loadtexture. (tout simplement)
    C'est la derniere partie de code que j'ai posté
    Certes, mais je ne vois aucune fonctions OpenGL.
    Regarde mon code. J'utilise "glDeleteTextures", "glGenTextures", " glBindTexture", "glTexParameteri", ...

    L'urgent est fait, l'impossible est en cours, pour les miracles prévoir un délai. ___ Écrivez dans un français correct !!

    C++Builder 5 - Delphi 6#2 Entreprise - Delphi 2007 Entreprise - Delphi 2010 Architecte - Delphi XE Entreprise - Delphi XE7 Entreprise - Delphi 10 Entreprise - Delphi 10.3.2 Entreprise - Delphi 10.4.2 Entreprise - Delphi 11.1 Entreprise
    OpenGL 2.1 - Oracle 10g - Paradox - Interbase (XE) - PostgreSQL (15.4)

  6. #6
    Membre actif Avatar de damienlann
    Profil pro
    Étudiant
    Inscrit en
    Mai 2005
    Messages
    293
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2005
    Messages : 293
    Points : 249
    Points
    249
    Par défaut
    Certes, mais je ne vois aucune fonctions OpenGL.
    c'est vrai ca...
    j'y regarde immediatement

  7. #7
    Membre actif Avatar de damienlann
    Profil pro
    Étudiant
    Inscrit en
    Mai 2005
    Messages
    293
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mai 2005
    Messages : 293
    Points : 249
    Points
    249
    Par défaut
    Ah oui désolé, j'ai pas tout posté.... à la fin du loadtexture je fait un createtexture comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    function CreateTexture(Width, Height, Format : Word; pData : Pointer) : Integer;
    var
      Texture : GLuint;
    begin
      glDeleteTextures(1, @Texture);
      glGenTextures(1, @Texture);
      glBindTexture(GL_TEXTURE_2D, Texture);
      glEnable( GL_TEXTURE_2D );
      glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      if Format = GL_RGBA then
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData)
      else
        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
     
      result :=Texture;
    end;
    voila je crois que maintenant il y a tout...
    encore une fois désolé
    donc la si j'ai bien compris je crée une 'mipmap' sur mon image.

Discussions similaires

  1. delphi et opengl
    Par yazid.dz dans le forum Débuter
    Réponses: 1
    Dernier message: 19/01/2013, 03h51
  2. [Delphi / DeviL / OpenGL] Problème Texture...
    Par tim53000 dans le forum Langage
    Réponses: 3
    Dernier message: 26/03/2009, 18h42
  3. [Delphi 2007][OpenGL] Détecter une pente
    Par zitezitoun dans le forum API, COM et SDKs
    Réponses: 8
    Dernier message: 13/06/2008, 11h43
  4. [3D] Loader un .3DS sous Delphi avec OpenGL
    Par frocket dans le forum OpenGL
    Réponses: 2
    Dernier message: 08/05/2006, 09h40
  5. Delphi - Fenêtre OpenGL dans PaintBox.
    Par joseph74 dans le forum OpenGL
    Réponses: 7
    Dernier message: 26/05/2004, 13h49

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo