PDA

View Full Version : c++Builder and glut librairy



chronos
05-28-2001, 04:21 AM
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.8);
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.58);
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;

}

Stonemaster
05-28-2001, 04:47 AM
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.

chronos
05-28-2001, 10:17 AM
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

http://www.opengl.org/discussion_boards/ubb/smile.gif

05-28-2001, 10:47 AM
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