I'm a beginer in OpenGl. I downloaded glut 3.7.6 package but I didn't find glu.h, glaux.h, opengl.h, opengl32.h and gl.h in there. Where can I get it ? And if I've found it, how to set it so it can work well. I'm using VC++ 2008 Express. Please tell me in detail about it. And about unistd.h file, where can I get it too? I downloaded a moon texture code from spacesimulator.net . I ran it and got the result below;

------ Build started: Project: tutorial4, Configuration: Debug Win32 ------
Compiling...
3dsloader.cpp
c:\documents and settings\satellite\my documents\spacesimulator.net-planetshading\3dsloader.cpp(26) : fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
texture.cpp
c:\documents and settings\satellite\my documents\spacesimulator.net-planetshading\texture.cpp(26) : fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory
tutorial4.cpp
c:\program files\microsoft visual studio 9.0\vc\include\stdlib.h(371) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs
c:\program files\microsoft sdks\windows\v6.0a\include\gl\glut.h(146) : see declaration of 'exit'
c:\program files\microsoft visual studio 9.0\vc\include\stdlib.h(371) : warning C4985: 'exit': attributes not present on previous declaration.
c:\program files\microsoft sdks\windows\v6.0a\include\gl\glut.h(146) : see declaration of 'exit'
c:\documents and settings\satellite\my documents\spacesimulator.net-planetshading\tutorial4.cpp(151) : error C3861: 'exit': identifier not found
Generating Code...
Build log was saved at "file://c:\Documents and Settings\SATELLITE\My Documents\spacesimulator.net-planetshading\Debug\BuildLog.htm"
tutorial4 - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Please help me.

Recommended Answers

unistd.h is a *nix-specific file and not supported by Microsoft compilers. I think Dev-C++ might support it though on Microsoft platform. More links about that here.

Jump to Post

All 4 Replies

unistd.h is a *nix-specific file and not supported by Microsoft compilers. I think Dev-C++ might support it though on Microsoft platform. More links about that here.

Visual Studio comes with OpenGL. Go search under the visual studio folder, you should be able to find those files.

GLUT is a third party utility tool supporting OpenGL that handles the user interface stuffs. It doesn't contain OpenGL files.

I've found what I want in
"http://www.swiftless.com/tutorials/opengl/gldrivers.html."
This link give me all except unistd.h.

I ran a simple gl code and it showed no problem. I mean I come in by double click the .c file which I want to build. If I want to make my own OpenGl Project, from where should I go. I still must look much for VC++ application.

Now I've the test code and I want to run it. First I go to File in VC++ 2008 toolbar, and then few options come up such as New -> Project
-> File
-> Project from existing code

I don't even know from where to start for my first OpenGl work. Then I tried to choose Project and there were some options too like ->CLR
->Win32
->General
What should I do. If I go to win 32 I'll be asked for few options again ->Win 32 console application
->Win 32 Project

I really want to know from where to go for my first code below and what kind of project that I should create coz I'm really dummy for this case.


Here it is the sample code that will work after finishing OpenGl setting;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#include <GL/glut.h>


/* 
 * Window properties 
 */
#define WINDOW_WIDTH    500
#define WINDOW_HEIGHT   500
#define WINDOW_X        100
#define WINDOW_Y        100
#define WINDOW_TITLE    "RGB-ColorCube"

/* 
 * Perspective properties 
 */
#define FOV_ANGLE       30

#define CENTER_X        0.0
#define CENTER_Y        0.0
#define CENTER_Z        0.0

#define VIEWER_X        0.0
#define VIEWER_Y        0.0
#define VIEWER_Z        -2.1

#define UP_X            0.0
#define UP_Y            1.0
#define UP_Z            0.0

#define CLIPPLANE_NEAR  1.0
#define CLIPPLANE_FAR   20.0

 
#define ROTATION_SPEED  2.0

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

GLfloat rot_x = 0.0, rot_y = 0.0;
GLfloat saved_x, saved_y;

/*
 * Material colors used for shading
 */
GLfloat red[4] = {.8, 0.0, 0.0, 1.0};
GLfloat white[4] = {.8, .8, .8, 1.0};

/*
 * Function prototypes
 */
void usage(void);
void draw_scene(void);
void draw_object(void);
void init(int argc, char **argv, void (*draw)(void));
void save_position(int button, int state, int x, int y);
struct point get_coords(double a, double b);
void vertex(double a, double b);
void rotate(int x, int y);
void set_color(int angle);

int main(int argc, char **argv) {
    /*
     * Init OpenGL and enter the event loop
     */
    init(argc, argv, draw_scene);

    return 0;
}

/*
 * Handle rotations and buffer swapping and call the function draw_object 
 * which does the actual drawing
 */
void draw_scene(void) {
    static GLfloat old_rot_matrix[16];
    static int initialized = 0;
    GLfloat new_rot_matrix[16];

    /* calculate new rotation matrix */
    glPushMatrix();
    glLoadIdentity();
    glRotatef(rot_x, 1.0, 0.0, 0.0);
    glRotatef(rot_y, 0.0, 1.0, 0.0);
    glGetFloatv(GL_MODELVIEW_MATRIX, new_rot_matrix);
    glPopMatrix();
    
    /* calculate total rotation */
    glPushMatrix();
    glLoadIdentity();
    glMultMatrixf(new_rot_matrix);
    if (initialized) {
      glMultMatrixf(old_rot_matrix);
    }

    glGetFloatv(GL_MODELVIEW_MATRIX, old_rot_matrix);
    initialized = 1;
    glPopMatrix();

    glPushMatrix();
    glMultMatrixf(old_rot_matrix); 

    draw_object();

    glPopMatrix();
    glFlush();
    glutSwapBuffers();
}

/*
 * Initialize the OpenGL machine
 */
void init(int argc, char **argv, void (*draw)(void)) {
    GLfloat light0_pos[] = {100.0, 100.0, 100.0, 1.0};
    GLfloat light0_color[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat ambient_light[] = {0.8, 0.8, 0.8, 1.0};

    glutInit(&argc, argv);

    /* Create a window */
    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    glutInitWindowPosition(WINDOW_X, WINDOW_Y);
    glutCreateWindow(WINDOW_TITLE);
    glClearColor(0.0, 0.0, 0.0, 0.0);

    /* Set up some light sources */
    glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_light);

    glEnable(GL_LIGHT0);
    /* glEnable(GL_LIGHTING); */

    glEnable(GL_DEPTH_TEST);

    glShadeModel(GL_SMOOTH);

    /* Create a viewing frustum */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(FOV_ANGLE, WINDOW_WIDTH/WINDOW_HEIGHT, CLIPPLANE_NEAR, 
        CLIPPLANE_FAR);
    gluLookAt(VIEWER_X, VIEWER_Y, -VIEWER_Z, CENTER_X, CENTER_Y, CENTER_Z, 
        UP_X, UP_Y, UP_Z);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(VIEWER_X, VIEWER_Y, VIEWER_Z);

    glutDisplayFunc(draw);
    glutMouseFunc(save_position);
    glutMotionFunc(rotate);
    glutMainLoop();

    /* Not reached */
}

/*
 * Save the position of the mouse pointer where the bottun press occured
 */
void save_position(int button, int state, int x, int y) {
    if (state == GLUT_DOWN) {
        saved_x = x;
        saved_y = y;
    }
}

/*
 * Calculate the angle the object has rotated by since the last update
 */
void rotate(int x, int y) {
    rot_y = (GLfloat)(x - saved_x) * ROTATION_SPEED;
    rot_x = (GLfloat)(y - saved_y) * ROTATION_SPEED;
    saved_x = x;
    saved_y = y;
    
    glutPostRedisplay();
}

/*
 * Draw a object
 */
void draw_object(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_QUAD_STRIP);
   
      glNormal3f(0,0,1);
      
      glColor3f(0,0,0);
      glVertex3f(-0.5,-0.5,-0.5);
      
      glColor3f(0,1,0);
      glVertex3f(-0.5,0.5,-0.5);

      glColor3f(1,0,0);
      glVertex3f(0.5,-0.5,-0.5);

      glColor3f(1,1,0);
      glVertex3f(0.5,0.5,-0.5);
       
      glNormal3f(1,0,0);
      glColor3f(1,0,1);
      glVertex3f(0.5,-0.5,0.5);
      
      glColor3f(1,1,1);
      glVertex3f(0.5,0.5,0.5);    

      glNormal3f(0,0,1);
      glColor3f(0,0,1);
      glVertex3f(-0.5,-0.5,0.5);
      glColor3f(0,1,1);
      glVertex3f(-0.5,0.5,0.5);
      
      glNormal3f(-1,0,0);
      glColor3f(0,0,0);
      glVertex3f(-0.5,-0.5,-0.5);
      glColor3f(0,1,0);
      glVertex3f(-0.5,0.5,-0.5);

    glEnd();

    
   glBegin(GL_QUADS);
   
      glNormal3f(0,1,0);
      
      glColor3f(0,1,0);
      glVertex3f(-0.5,0.5,-0.5);
      
      glColor3f(0,1,1);
      glVertex3f(-0.5,0.5,0.5);

      glColor3f(1,1,1);
      glVertex3f(0.5,0.5,0.5);

      glColor3f(1,1,0);
      glVertex3f(0.5,0.5,-0.5);

    glEnd();

    glBegin(GL_QUADS);
   
      glNormal3f(0,-1,0);
      
      glColor3f(0,0,0);
      glVertex3f(-0.5,-0.5,-0.5);
      
      glColor3f(0,0,1);
      glVertex3f(-0.5,-0.5,0.5);

      glColor3f(1,0,1);
      glVertex3f(0.5,-0.5,0.5);

      glColor3f(1,0,0);
      glVertex3f(0.5,-0.5,-0.5);

    glEnd();
    
}

Use Win32 console application option, since you are using GLUT to handle the user interfaces.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.