Results 1 to 4 of 4

Thread: c++Builder and glut librairy

  1. #1
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    4

    c++Builder and glut librairy

    I show you my code.How can i include this code in C++Builder:
    #include <stdlib.h>
    #include <stdio.h>
    #include "glut.h"

    static int shoulder=0, elbow=0, coucou=0, poignee=0, pince=0, avant=0, toto=0;/* rectifier*/


    void init(void)
    {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);

    GLfloat mat_ambient[] ={0.5, 0.5, 0.5, 1.0};
    GLfloat mat_specular[] ={1.0, 1.0, 1.0, 1.0};
    GLfloat mat_shininess[] ={50};
    GLfloat light_position[] ={1.0, 1.0, 1.0, 1.0};
    GLfloat model_ambient[] ={0.5, 0.5, 0.5, 1.0};

    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);


    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);



    }

    ///////////////////////////////////////////////////////////////////////////////////////
    ///////////////* FONCTION PERMETTANT DE LIRE LES COORDONNEES */////////////////////////
    ///////////////////////*RECU DU POSTE DE PILOTAGE*/////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////////
    ///////////////* FONCTION PERMETTANT DE LIRE LES COORDONNEES */////////////////////////
    //////////////////*RECU DU POSTE DE VISION ARTIFICIELLE*///////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////////////////////////////////////
    /////////////* FONCTION REPRESENTANT LES DIFFERENTES PARTIS DU ROBOT */////////////////
    ///////////////////////////////////////////////////////////////////////////////////////
    void display(void)
    {



    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_TEXTURE_2D);

    glBegin(GL_QUADS);

    glColor3f(1.0,0.0,0.0);
    glVertex3f(-3.0, -2.4, 3.0);
    glVertex3f(3.0, -2.4, 3.0);
    glVertex3f(3.0, -2.4, -3.0);
    glVertex3f(-3.0, -2.4, -3.0);



    glEnd();
    glFlush();
    glDisable(GL_TEXTURE_2D);
    /* CYLINDRE DE BASE */
    glPushMatrix();
    GLUquadricObj *qobj;
    qobj =gluNewQuadric();

    gluQuadricDrawStyle (qobj, GLU_FILL);
    glRotatef(90.0, 1.0, 0.0, 0.0);
    gluCylinder (qobj, 0.2, 0.2, 1.5, 25, 5);


    glRotatef ((GLfloat)coucou, 0.0, 1.0, 0.0);
    glPopMatrix();

    glPopMatrix();
    gluDeleteQuadric(qobj);

    /* REPRESENTATION DU BRAS */

    glPushMatrix();
    glRotatef ((GLfloat) coucou, 0.0 , 1.0, 0.0);
    glTranslatef(0.0, -0.2, -0.;
    glRotatef ((GLfloat) shoulder, 0.0 , 0.0, -1.0);
    glPushMatrix();
    glScalef(2.2, 0.4, 1.0);
    glutSolidCube(1.1);


    /* REPRESENTATION DE L'AVANT BRAS */

    glRotatef ((GLfloat) coucou, 0.0 , 1.0, 0.0);

    glPopMatrix();

    glTranslatef(1.1, 0.0, 0.0);
    glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
    glTranslatef(0.0, 0.0, 1.0);
    glPushMatrix();
    glScalef(1.4, 0.4, 1.0);
    glutSolidCube(1.0);
    glPopMatrix();

    /* REPRESENTATION DE LA PINCE */
    glPushMatrix();

    glRotatef(90.0, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 0.5;
    glRotatef((GLfloat)avant, 1.0, 0.0, 0.0);
    glRotatef((GLfloat)poignee,0.0, 0.0, 1.0);
    gluCylinder (qobj, 0.05, 0.05, 0.3, 25, 5);

    glTranslatef(0.0, 0.15, 0.5);

    glScalef(0.3, 0.07, 0.3);
    glutSolidCube(1.0);

    /**/
    glTranslatef(0.0, -4.0, 0.0);
    glScalef(1.0, 0.8, 1.0);
    glutSolidCube(1.0);

    /**/



    glPopMatrix();
    glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();



    /* REPRESENTATION DE LA PIECE A DEPLACER */

    }



    //////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////* FONCTION PERMETTANT DE FACONNER *///////////////////////
    ///////////////////////////////*LA REPRESENTATION GRAPHIQUE*/////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////
    void reshape(int w, int h)
    {

    glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(65.0, ((GLfloat) w/(GLfloat) h), 1.0, 20.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0, 0.0, -7.0);
    glRotatef(30.0,1.0,0.0,0.0);

    }

    void keyboard(unsigned char key, int x, int y) /* a titre d'essai*/
    {
    switch (key)
    {
    case 's':
    shoulder =(shoulder + 5) % 360;

    glutPostRedisplay();
    break;
    case 'S':
    shoulder = (shoulder-5) % 360;

    glutPostRedisplay();
    break;
    case 'e':
    elbow = (elbow - 5) % 360;
    glutPostRedisplay();
    break;
    case 'E':

    elbow = (elbow + 5) % 360;
    glutPostRedisplay();
    break;
    case 't':

    coucou = (coucou + 5) % 360;
    glutPostRedisplay();
    break;
    case 'T':

    coucou = (coucou - 5) % 360;
    glutPostRedisplay();
    break;
    case 'x':

    poignee = (poignee - 5) % 360;
    glutPostRedisplay();
    break;
    case 'X':

    poignee = (poignee + 5) % 360;
    glutPostRedisplay();
    break;
    case 'a':

    avant = (avant + 5) % 360;
    glutPostRedisplay();
    break;
    case 'A':

    avant = (avant - 5) % 360;
    glutPostRedisplay();
    break;
    case 'o':

    shoulder=0;
    elbow=0;
    coucou=0;
    poignee=0;
    pince=0;
    avant=0;
    glutPostRedisplay();
    break;


    default:
    break;
    }

    }

    //////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////**/////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////
    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("ROBOT");
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutKeyboardFunc(keyboard);
    glutMainLoop();
    return 0;

    }

  2. #2

    Re: c++Builder and glut librairy

    I had some problems to create an application with C++ Builder that uses GLUT. It is Better to use the Win32 API only without a console window. Take a look at nehe.gamedev.net, there you will find code for C++Builder using the "pure" Win32 API. If you really want to use GLUT, create a new console application: File->New and then on Console Expert or something like this. Then only copy your code into the codewindow. I had only problems and the program never managed to run. Anyway I recommend to use VC++ when using OpenGL. You also find more example projects for it.

    Bye and tell me if it worked,
    -Stone.

  3. #3
    Junior Member Newbie
    Join Date
    May 2001
    Location
    France
    Posts
    4

    Re: c++Builder and glut librairy

    Stonemaster Thank but it doesn't work with console Application but it work with visual c++ 6.
    I must use builder C++ and Nehe's web page is not available.If you have news answer me.
    Nb:My Outlook don't work


  4. #4
    Guest

    Re: c++Builder and glut librairy

    It is a small problem using C++ glut programs and Builder. You can solve it by replacing "#if 0" with "#if 1" somewhere at the beginning of glut.h

Similar Threads

  1. how to use GLUT in c++builder
    By seabridge in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-01-2004, 12:31 PM
  2. How should I use glut library in C++ Builder?
    By linusky in forum OpenGL: Windows
    Replies: 1
    Last Post: 03-29-2004, 06:15 AM
  3. Glut + C++ Builder 6.0
    By in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 06-21-2003, 08:58 AM
  4. Builder &Glut
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-24-2001, 07:32 AM
  5. glut with Builder C++
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-19-2001, 07:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean