PDA

View Full Version : Open GL under Dos ??



07-16-2000, 02:33 AM
OK,
I guess it sounds strange, but I would like to know how to use Open Gl under the Dos system because I guess it will be easier to handle all the events that can happen. I
hope someone is able to write me simple C++ code ( Im using Turbo C++ 4.5 so Im able to compile programms for Dos ).
Thanks alot for even thinking bout it.

nexusone
07-16-2000, 03:16 AM
I have not tried it, but I think that you only need to download the opengl library and header files.
Just add the gl.h, glu.h and glaux.h headers to your program. Now if I am not wrong about this you will not be able to use the glut library becouse it is based for use with windows.
One other thing is that you are using Turbo C++, you may need to find a copy of the gl library files compiled for use with Turbo C++, because I am not sure the ones for Microsoft VC++ will work with Turbo C.
But will not hurt to try or maybe someone else can anwser this.
Try this:
/*
* (c) Copyright 1993-1995 Microsoft Corporation
*
* bgammon.c
*
* start easy, just have pieces...
*
*/
#include "glos.h"

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>

GLvoid initialize(GLvoid);
GLvoid CALLBACK drawScene(GLvoid);
GLvoid CALLBACK resize(GLsizei, GLsizei);
GLvoid drawLight(GLvoid);
void polarView( GLdouble, GLdouble, GLdouble, GLdouble);

GLfloat latitude, longitude, radius;

void _CRTAPI1 main(void)
{
initialize();

auxMainLoop( drawScene );
}

GLvoid CALLBACK resize( GLsizei width, GLsizei height )
{
GLfloat aspect;

glViewport( 0, 0, width, height );

aspect = (GLfloat) width / height;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, aspect, 3.0, 7.0 );
glMatrixMode( GL_MODELVIEW );
}

GLvoid initialize(GLvoid)
{
GLfloat maxObjectSize, aspect;
GLdouble near_plane, far_plane;
GLsizei width, height;

GLfloat ambientProperties[] = {0.7, 0.7, 0.7, 1.0};
GLfloat diffuseProperties[] = {0.8, 0.8, 0.8, 1.0};
GLfloat specularProperties[] = {1.0, 1.0, 1.0, 1.0};

width = 1024.0;
height = 768.0;

auxInitPosition( width/4, height/4, width/2, height/2);

auxInitDisplayMode( AUX_RGB | AUX_DEPTH | AUX_DOUBLE );

auxInitWindow( "AUX Library Demo" );

auxIdleFunc( drawScene );

auxReshapeFunc( resize );

glClearColor( 0.0, 0.0, 0.0, 1.0 );
glClearDepth( 1.0 );

glEnable(GL_DEPTH_TEST);

glEnable(GL_LIGHTING);

glLightfv( GL_LIGHT0, GL_AMBIENT, ambientProperties);
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseProperties);
glLightfv( GL_LIGHT0, GL_SPECULAR, specularProperties);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0);

glEnable( GL_LIGHT0 );

glMatrixMode( GL_PROJECTION );
aspect = (GLfloat) width / height;
gluPerspective( 45.0, aspect, 3.0, 7.0 );
glMatrixMode( GL_MODELVIEW );

near_plane = 3.0;
far_plane = 7.0;
maxObjectSize = 3.0;
radius = near_plane + maxObjectSize/2.0;

latitude = 0.0;
longitude = 0.0;


}

void polarView(GLdouble radius, GLdouble twist, GLdouble latitude,
GLdouble longitude)
{
glTranslated(0.0, 0.0, -radius);
glRotated( -twist, 0.0, 0.0, 1.0 );
glRotated( -latitude, 1.0, 0.0, 0.0);
glRotated( longitude, 0.0, 0.0, 1.0);

}

GLvoid CALLBACK drawScene(GLvoid)
{
static GLfloat whiteAmbient[] = {0.3, 0.3, 0.3, 1.0};
static GLfloat redAmbient[] = {0.3, 0.1, 0.1, 1.0};
static GLfloat greenAmbient[] = {0.1, 0.3, 0.1, 1.0};
static GLfloat blueAmbient[] = {0.1, 0.1, 0.3, 1.0};
static GLfloat whiteDiffuse[] = {1.0, 1.0, 1.0, 1.0};
static GLfloat redDiffuse[] = {1.0, 0.0, 0.0, 1.0};
static GLfloat greenDiffuse[] = {0.0, 1.0, 0.0, 1.0};
static GLfloat blueDiffuse[] = {0.0, 0.0, 1.0, 1.0};
static GLfloat whiteSpecular[] = {1.0, 1.0, 1.0, 1.0};
static GLfloat redSpecular[] = {1.0, 0.0, 0.0, 1.0};
static GLfloat greenSpecular[] = {0.0, 1.0, 0.0, 1.0};
static GLfloat blueSpecular[] = {0.0, 0.0, 1.0, 1.0};

static GLfloat lightPosition0[] = {1.0, 1.0, 1.0, 1.0};
static GLfloat angle = 0.0;

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glPushMatrix();

latitude += 4.0;
longitude += 2.5;

polarView( radius, 0, latitude, longitude );

glPushMatrix();
angle += 6.0;
glRotatef(angle, 1.0, 0.0, 1.0);
glTranslatef( 0.0, 1.5, 0.0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0);
drawLight();
glPopMatrix();

glPushAttrib(GL_LIGHTING_BIT);

glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, redAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, redDiffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, whiteSpecular);
glMaterialf(GL_FRONT, GL_SHININESS, 100.0);

auxSolidCone( 0.3, 0.6 );

glPopAttrib();
auxWireSphere(1.5);

glPushAttrib(GL_LIGHTING_BIT);

glMaterialfv(GL_BACK, GL_AMBIENT, greenAmbient);
glMaterialfv(GL_BACK, GL_DIFFUSE, greenDiffuse);
glMaterialfv(GL_FRONT, GL_AMBIENT, blueAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, blueDiffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, blueSpecular);
glMaterialf(GL_FRONT, GL_SHININESS, 50.0);

glPushMatrix();
glTranslatef(0.8, -0.65, 0.0);
glRotatef(30.0, 1.0, 0.5, 1.0);
auxSolidCylinder( 0.3, 0.6 );
glPopMatrix();

glPopAttrib();


glPopMatrix();

auxSwapBuffers();
}

GLvoid drawLight(GLvoid)
{
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glColor3f(1.0, 1.0, 1.0);
auxSolidDodecahedron(0.1);
glPopAttrib();
}

Bob
07-16-2000, 04:45 AM
All OpenGL libraries is using some kind of external driver (either MS's own software, or HW manufacturers own drivers, or something similar). And all these drivers is Windowsbased, i.e. no dos-functionality.

To code for dos, you can download Mesa 3D (http://mesa3d.sourceforge.net) , which have separate drivers for dos.

And no, GLUT won't work under dos.

And there will be VERY (if not impossible) to get hardwareacceleration under dos, unless you are using glide-drivers and Mesa 3D. But then you must have a 3Dfx-based card.

nexusone
07-16-2000, 07:00 AM
Thanks for the input, I was sure about glut not working. Not so sure about the other.


Originally posted by Bob:
All OpenGL libraries is using some kind of external driver (either MS's own software, or HW manufacturers own drivers, or something similar). And all these drivers is Windowsbased, i.e. no dos-functionality.

To code for dos, you can download Mesa 3D (http://mesa3d.sourceforge.net) , which have separate drivers for dos.

And no, GLUT won't work under dos.

And there will be VERY (if not impossible) to get hardwareacceleration under dos, unless you are using glide-drivers and Mesa 3D. But then you must have a 3Dfx-based card.

Galileo430
07-17-2000, 04:05 PM
DOS is DEAD!!!!