PDA

View Full Version : problem on programming in redhat9



forfan
08-06-2003, 06:50 PM
Hi, I am a beginning of OpenGL programmer.
My os is redhat9.
Here is a test code with compile errer like the
following:

firstMesa.c: In function `Key':
firstMesa.c:104: `tk_ESCAPE' undeclared (first use in this function)
firstMesa.c:104: (Each undeclared identifier is reported only once
firstMesa.c:104: for each function it appears in.)
firstMesa.c:106: parse error before ';' token
firstMesa.c:108: `TK_LEFT' undeclared (first use in this function)
firstMesa.c:111: `TK_RIGHT' undeclared (first use in this function)
firstMesa.c:114: `TK_UP' undeclared (first use in this function)
firstMesa.c:117: `TK_DOWN' undeclared (first use in this function)
firstMesa.c:120: `TK_z' undeclared (first use in this function)
firstMesa.c:123: `TK_Z' undeclared (first use in this function)
firstMesa.c:126: `TK_s' undeclared (first use in this function)
firstMesa.c:127: `TK_S' undeclared (first use in this function)
firstMesa.c:130: `TK_w' undeclared (first use in this function)
firstMesa.c:131: `TK_W' undeclared (first use in this function)
firstMesa.c: In function `main':
firstMesa.c:174: `TK_DEPTH' undeclared (first use in this function)
firstMesa.c:175: `TK_RGB' undeclared (first use in this function)
firstMesa.c:175: `TK_INDEX' undeclared (first use in this function)
firstMesa.c:176: `TK_DOUBLE' undeclared (first use in this function)
firstMesa.c:176: `TK_SINGLE' undeclared (first use in this function)
firstMesa.c:177: `TK_DIRECT' undeclared (first use in this function)
firstMesa.c:177: `TK_INDIRECT' undeclared (first use in this function)
firstMesa.c:167: warning: return type of `main' is not `int'


The following is my source code:
=============================
#include "/usr/include/GL/GLwDrawAP.h"
#include "/usr/include/GL/GLwMDrawA.h"
#include "/usr/include/GL/GLwMDrawAP.h"
#include "/usr/include/GL/gl.h"
#include "/usr/include/GL/glext.h"
#include "/usr/include/GL/glu.h"
#include "/usr/include/GL/glx.h"
#include "/usr/include/GL/glxext.h"
#include "/usr/include/GL/glxint.h"
#include "/usr/include/GL/glxmd.h"
#include "/usr/include/GL/glxtokens.h"
#include "/usr/include/GL/osmesa.h"

GLenum rgb,doubleBuffer,directRender;
float rotateX=0,rotateY=0,rotateZ=0;
int BoxType=1;
void Init(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glClearColor(1.0,1.0,1.0,0);
glClearDepth(1.0);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
}

void DrawScene(void){
Init();
glPushMatrix();
glRotatef(rotateX,1,0,0);
glRotatef(rotateY,0,1,0);
glRotatef(rotateZ,0,0,1);
if(BoxType==1){
glColor3f(1.0,0.0,1.0);
glPushMatrix();glTranslatef(13.5,17,0);tkSolidSphe re(1,0.7);glPopMatrix();
glColor3f(0.8,0.0,0.2);
glPushMatrix();glTranslatef(0,8,0);tkSolidBox(1,1, 16,4);glPopMatrix();
glPushMatrix();glTranslatef(16,8,0);tkSolidBox(1,1 ,16,4);glPopMatrix();
glPushMatrix();glTranslatef(6,16,0);tkSolidBox(1,1 3,1,4);glTranslatef(9.5,0,0);tkSolidBox(1,2,1,4);g lPopMatrix();
glPushMatrix();glTranslatef(0.5,0,0);tkSolidBox(1, 2,1,4);glPopMatrix();tkSolidBox(1,13,1,4);glPopMat rix();
glColor3f(0.0,0.5,0.0);
glPushMatrix();glTranslatef(6,14,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
glPushMatrix();glTranslatef(5,12,0);tkSolidBox(1,3 ,1,4);glPopMatrix();
glPushMatrix();glTranslatef(3,12,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
glPushMatrix();glTranslatef(3,8,0);tkSolidBox(1,5, 1,4);glPopMatrix();
glPushMatrix();glTranslatef(5,8,0);tkSolidBox(1,1, 4,4);glPopMatrix();
glPushMatrix();glTranslatef(8,6,0);tkSolidBox(1,7, 1,4);glPopMatrix();
glPushMatrix();glTranslatef(11,9,0);tkSolidBox(1,1 ,5,4);glPopMatrix();
glPushMatrix();glTranslatef(11,11,0);tkSolidBox(1, 2,1,4);glPopMatrix();
glPushMatrix();glTranslatef(12,13,0);tkSolidBox(1, 7,1,4);glPopMatrix();
glPushMatrix();glTranslatef(8,11,0);tkSolidBox(1,1 ,5,4);glPopMatrix();
glPushMatrix();glTranslatef(3,4,0);tkSolidBox(1,1, 3,4);glPopMatrix();
glPushMatrix();glTranslatef(8,3,0);tkSolidBox(1,10 ,1,4);glPopMatrix();
glPushMatrix();glTranslatef(13,4,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
glPushMatrix();glTranslatef(11,2,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
}
else
{
glColor3f(1.0,0.0,1.0);
glPushMatrix();glTranslatef(2.5,-1,0);tkWireSphere(1,0.7);glPopMatrix();
glColor3f(0.8,0.0,0.2);
glPushMatrix();glTranslatef(0,8,0);tkWireBox(1,1,1 6,4);glPopMatrix();
glPushMatrix();glTranslatef(16,8,0);tkWireBox(1,1, 16,4);glPopMatrix();
glPushMatrix();glTranslatef(6,16,0);tkSolidBox(1,1 3,1,4);glTranslatef(9.5,0,0);tkSolidBox(1,2,1,4);g lPopMatrix();
glPushMatrix();glTranslatef(0.5,0,0);tkSolidBox(1, 2,1,4);glPopMatrix();tkSolidBox(1,13,1,4);glPopMat rix();
glColor3f(0.0,0.5,0.0);
glPushMatrix();glTranslatef(6,14,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
glPushMatrix();glTranslatef(5,12,0);tkSolidBox(1,3 ,1,4);glPopMatrix();
glPushMatrix();glTranslatef(3,12,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
glPushMatrix();glTranslatef(3,8,0);tkSolidBox(1,5, 1,4);glPopMatrix();
glPushMatrix();glTranslatef(5,8,0);tkSolidBox(1,1, 4,4);glPopMatrix();
glPushMatrix();glTranslatef(8,6,0);tkSolidBox(1,7, 1,4);glPopMatrix();
glPushMatrix();glTranslatef(11,9,0);tkSolidBox(1,1 ,5,4);glPopMatrix();
glPushMatrix();glTranslatef(11,11,0);tkSolidBox(1, 2,1,4);glPopMatrix();
glPushMatrix();glTranslatef(12,13,0);tkSolidBox(1, 7,1,4);glPopMatrix();
glPushMatrix();glTranslatef(8,11,0);tkSolidBox(1,1 ,5,4);glPopMatrix();
glPushMatrix();glTranslatef(3,4,0);tkSolidBox(1,1, 3,4);glPopMatrix();
glPushMatrix();glTranslatef(8,3,0);tkSolidBox(1,10 ,1,4);glPopMatrix();
glPushMatrix();glTranslatef(13,4,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
glPushMatrix();glTranslatef(11,2,0);tkSolidBox(1,1 ,3,4);glPopMatrix();
}
glPopMatrix();
glFlush();
if(doubleBuffer){
tkSwapBuffers();
}
}

void Reshape(int width,int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width<=height)
glOrtho(-4,20,-4*(GLfloat)height/(GLfloat)width,20*(GLfloat)height/(GLfloat)width,-10,10);
else
glOrtho(-4*(GLfloat)height/(GLfloat)width,20*(GLfloat)height/(GLfloat)width,-4,20,-10,10);
glMatrixMode(GL_MODELVIEW);
}
static GLenum Key(int key,GLenum mask)
{
switch (key)
{
case ESCAPE:
case
tkQuit();
break;
case TK_LEFT:
rotateY-=5;
break;
case TK_RIGHT:
rotateY+=5;
break;
case TK_UP:
rotateX+=5;
break;
case TK_DOWN:
rotateX-=5;
break;
case TK_z:
rotateZ-=5;
break;
case TK_Z:
rotateZ+=5;
break;
case TK_s:
case TK_S:
BoxType=1;
break;
case TK_w:
case TK_W:
BoxType=2;
break;
default:
return GL_FALSE;
}
return GL_TRUE;
}
static GLenum Args(int argc,char** argv)
{
GLint ii;
rgb=GL_TRUE;
doubleBuffer=GL_FALSE;
directRender=GL_TRUE;
for(ii=1;ii<argc;ii++){
if (strcmp(argv[ii],"-ci")==0){
rgb=GL_FALSE;
}else if (strcmp(argv[ii],"-rgb")==0){
rgb=GL_TRUE;
}else if(strcmp(argv[ii],"-sb")==0){
doubleBuffer=GL_FALSE;
}else if(strcmp(argv[ii],"-db")==0){
doubleBuffer=GL_TRUE;
}else if(strcmp(argv[ii],"-dr")==0){
directRender=GL_TRUE;
}else if(strcmp(argv[ii],"-ir")==0){
directRender=GL_FALSE;
}else{
printf("%s(Bad option).\n",argv[ii]);
return GL_FALSE;
}
}
return GL_TRUE;
}

void main(int argc,char** argv)
{
GLenum type;
if (Args(argc,argv)==GL_FALSE){
tkQuit();
}

tkInitPosition(0,0,400,400);
type-TK_DEPTH;
type|=(rgb)?TK_RGB:TK_INDEX;
type|=(doubleBuffer)?TK_DOUBLE:TK_SINGLE;
type|=(directRender)?TK_DIRECT:TK_INDIRECT;

tkInitDisplayMode(type);

if (tkInitWindow("Maze")==GL_FALSE){
tkQuit();
}
Init();
tkExposeFunc(Reshape);
tkReshapeFunc(Reshape);

tkKeyDownFunc(Key);

tkDisplayFunc(DrawScene);
tkExec();
}

nexusone
08-07-2003, 03:58 AM
The compiler is looking for the "tk" library files.

I also use RH 9.0 but I have not used this library, but it looks like your missing a include file that defines the tk routines, I did not see any #include<tk??.h>. Check and see if there is a include file for the tk stuff.



[This message has been edited by nexusone (edited 08-07-2003).]

forfan
08-07-2003, 05:44 AM
Thank you very much.
In fact, the coding should include a "gltk.h" file, but redhat9 doesn't have this file.

I wonder that there is another way to
make the code work.



Originally posted by nexusone:
The compiler is looking for the "tk" library files.

I also use RH 9.0 but I have not used this library, but it looks like your missing a include file that defines the tk routines, I did not see any #include<tk??.h>. Check and see if there is a include file for the tk stuff.

[This message has been edited by nexusone (edited 08-07-2003).]

Deiussum
08-07-2003, 06:03 AM
Originally posted by forfan:
Thank you very much.
In fact, the coding should include a "gltk.h" file, but redhat9 doesn't have this file.

I wonder that there is another way to
make the code work.




There are a couple of options.

1. Get the TK library for RedHat. I'm not familiar with this library either, but I'm sure it's easily obtainable.

2. Convert the TK code over to use something like glut, SDL, FLFW, glx, etc..

nexusone
08-07-2003, 06:30 AM
The tk functions look very close to functions found in GLUT, the only problem there is a bug in the glut shipped with RH 9.0 and you have to download a version earlier then 9.0 for it to compile.



Originally posted by Deiussum:
There are a couple of options.

1. Get the TK library for RedHat. I'm not familiar with this library either, but I'm sure it's easily obtainable.

2. Convert the TK code over to use something like glut, SDL, FLFW, glx, etc..