Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Utilisation de OpenGL  (Read 2897 times)

0 Members and 1 Guest are viewing this topic.

Pierleur

  • Newbie
  • *
  • Posts: 2
    • View Profile
Utilisation de OpenGL
« on: April 05, 2016, 08:08:06 pm »
Bonjour, je cherche a utilisé une fenêtre SFML avec OpenGL. Après quelque test je n'arrive pas à activer le test de pronfondeur. Voici mon code :
#include <SFML/Window.hpp>
#include <GL/gl.h>
#include <GL/glu.h>
#include <cstdlib>

using namespace std;
using namespace sf;

int main()
{
    Window window(VideoMode(640,480),"Yolo");

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective(70,(double)640/480,1,10);
    glEnable(GL_DEPTH_TEST);

    while (true)
    {
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity( );

    gluLookAt(3,4,2,0,0,0,0,0,1);

    glBegin(GL_QUADS);

    glColor3ub(255,0,0); //face rouge
    glVertex3d(1,1,1);
    glVertex3d(1,1,-1);
    glVertex3d(-1,1,-1);
    glVertex3d(-1,1,1);

    glColor3ub(0,0,255); //face bleue
    glVertex3d(-1,-1,1);
    glVertex3d(-1,-1,-1);
    glVertex3d(1,-1,-1);
    glVertex3d(1,-1,1);

    glEnd();

    glFlush();
        window.display();
    }

    return 0;
}
 

Si je demande de l'aide ici, c'est que cela marche dans une fenêtre SDL:
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <cstdlib>

int main(int argc, char *argv[])
{
    SDL_Event event;

    SDL_Init(SDL_INIT_VIDEO);
    atexit(SDL_Quit);
    SDL_WM_SetCaption("SDL GL Application", NULL);
    SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective(70,(double)640/480,1,10);
    glEnable(GL_DEPTH_TEST);

    while (true)
    {
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity( );

    gluLookAt(3,4,2,0,0,0,0,0,1);

    glBegin(GL_QUADS);

    glColor3ub(255,0,0); //face rouge
    glVertex3d(1,1,1);
    glVertex3d(1,1,-1);
    glVertex3d(-1,1,-1);
    glVertex3d(-1,1,1);

    glColor3ub(0,0,255); //face bleue
    glVertex3d(-1,-1,1);
    glVertex3d(-1,-1,-1);
    glVertex3d(1,-1,-1);
    glVertex3d(1,-1,1);

    glEnd();

    glFlush();
    SDL_GL_SwapBuffers();
    }

    return 0;
}

Comment puis-je règler se problème ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re : Utilisation de OpenGL
« Reply #1 on: April 05, 2016, 08:23:25 pm »
Créer un contexte avec depth buffer serait un bon départ.

http://www.sfml-dev.org/tutorials/2.3/window-opengl-fr.php#crceer-une-fencotre-opengl
Laurent Gomila - SFML developer

Pierleur

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re : Utilisation de OpenGL
« Reply #2 on: April 05, 2016, 10:16:27 pm »
Sa marche tout de suite mieux. Merci pour cette réponse aussi rapide que efficace et j'en profite pour vous remerciez aussi pour nous procurez une superbe bibliothèque complète et de qualité.

 

anything