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

3D Java Discussion :

Basic OpenGL Rendering using LWJGL


Sujet :

3D Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 11
    Par défaut Basic OpenGL Rendering using LWJGL
    Bonjour, j'aimerai réaliser un cube en 3d avec openGL (LWJGL)
    Lorsqu'il s'agit de 2D, il n'y a pas le moindre probleme mais le passage à la 3d s'avere plus compliqué
    Pour résumer je ne vois que quelques arretes de mon cube, peut etre est ce un probleme de vue?
    Merci de me préciser si erreur il y a...

    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
    64
    65
    66
    67
    68
     
    private static void render() {
        // clear the screen
    	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
     
        // center square according to screen size
        GL11.glPushMatrix();
        GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
     
          // rotate square according to angle
         //GL11.glRotatef(angle, 0, 0, 1.0f);
     
          // render the square
     
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
         GLU.gluLookAt(5,0,1,0,5,0,0,1,0);
     
          GL11.glBegin(GL11.GL_QUADS);
     
     
          GL11.glColor3d(1,0,0);
          GL11.glVertex3i(50,50,50);
          GL11.glVertex3i(50,-50,50);
          GL11.glVertex3i(-50,-50,50);
          GL11.glVertex3i(-50,50,50);
          	//1 face
     
          GL11.glColor3d(0,1,0);
          GL11.glVertex3i(50,50,-50);
          GL11.glVertex3i(50,-50,-50);
          GL11.glVertex3i(-50,-50,-50);
          GL11.glVertex3i(-50,50,-50);
          	//2 faces
     
          GL11.glColor3d(0,0,1);
          GL11.glVertex3i(50,50,50);
          GL11.glVertex3i(50,-50,50);
          GL11.glVertex3i(50,-50,-50);
          GL11.glVertex3i(50,50,-50);
          	//3 faces
     
          GL11.glColor3d(0,1,1);
          GL11.glVertex3i(-50,50,50);
          GL11.glVertex3i(-50,-50,50);
          GL11.glVertex3i(-50,-50,-50);
          GL11.glVertex3i(-50,50,-50);
          	//4 faces
     
          GL11.glColor3d(1,0,0);
          GL11.glVertex3i(-50,50,-50);
          GL11.glVertex3i(-50,50,50);
          GL11.glVertex3i(50,50,50);
          GL11.glVertex3i(50,50,-50);
          	//5 faces
     
          GL11.glColor3d(1,1,0);
          GL11.glVertex3i(-50,-50,-50);
          GL11.glVertex3i(-50,-50,50);
          GL11.glVertex3i(50,-50,50);
          GL11.glVertex3i(50,-50,-50);
     
          GL11.glEnd();
     
        GL11.glPopMatrix();
      }
     
    }

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 11
    Par défaut
    au cas ou cela interesserait quelqu'un voila globalement la solution au probleme donné

    il convenait de remplacer la partie de code suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    // center square according to screen size
        GL11.glPushMatrix();
        GL11.glTranslatef(Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
     
          // rotate square according to angle
         GL11.glRotatef(angle, 0, 0, 1.0f);
     
          // render the square
     
         GL11.glMatrixMode(GL11.GL_MODELVIEW);
         GLU.gluLookAt(1,1,1,0,0,0,1,1,0);
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
            GL11.glMatrixMode(GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, 1f, 1f, 5000f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
     
            GL11.glLoadIdentity();
     
            GL11.glPushMatrix();
            GLU.gluLookAt(0, 0, -1000, 0, 0, 0, 0, 1, 0);
     
            // rotate square according to angle
            GL11.glRotatef(angle, 0, 0, 1.0f);
    en bref la methode gluPerspective y permet de passer outre ce probleme sous lwgjl...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     GLU.gluPerspective(45.0f, 1f, 1f, 5000f);

Discussions similaires

  1. OpenGl rendering dans une form créée dynamiquement
    Par hey_monkey dans le forum Débuter
    Réponses: 5
    Dernier message: 14/12/2011, 11h07
  2. Réponses: 2
    Dernier message: 15/06/2007, 08h49
  3. Réponses: 4
    Dernier message: 20/04/2005, 13h30
  4. OpenGL et Visual Basic .Net
    Par MatP dans le forum OpenGL
    Réponses: 4
    Dernier message: 15/12/2004, 13h51
  5. Opengl et Visual basic
    Par Cazman dans le forum OpenGL
    Réponses: 6
    Dernier message: 21/04/2004, 14h58

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