they work without GLUT, but you should have installed your graphic card properly or it will be VERY slow.
tschö, Bero

[edited by - Bero_Avrion on June 9, 2003 3:21:59 PM]
quote:
Original post by Anonymous Poster
congradulations on venturing into linux. But I would recomend learning to program in C/C++ before trying to do any graphics/game programming.
#ifdef WIN32 #include "windows.h" //Just in case we are compiligng on windows#endif#include <iostream>#include <GL/gl.h> //Standard include#include <GL/glu.h> //Standard Include#include <SDL/SDL.h> //Standard Include//These all define the screen setup#define SCREEN_WIDTH 640#define SCREEN_HEIGHT 480#define SCREEN_BPP 16//Used in some functions#define TRUE 1#define FALSE 0using namespace std;SDL_Surface *surface;int i = 0;GLenum mode = GL_POINTS;GLfloat yrot = 0.0;// Quit nicelyvoid Quit(int returnCode){ SDL_Quit(); exit(returnCode);}// As with all opengl programs, the resize functionint resizeWindow(int width, int height){ GLfloat ratio; if(height == 0) height = 1; ratio = (GLfloat)width / (GLfloat)height; glViewport(0,0,(GLint)width, (GLint)height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0f, ratio, 0.1f, 100.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return(TRUE);}// Function to handle key pressesvoid handleKeyPress(SDL_keysym *keysym){ switch(keysym->sym) { case SDLK_ESCAPE: Quit(0); break; case SDLK_F1: SDL_WM_ToggleFullScreen(surface); break; case SDLK_n: i++; i %= 10; cout << "i is " << i << endl; break; default: break; } switch(i) { case 0: mode = GL_POINTS; break; case 1: mode = GL_LINES; break; case 2: mode = GL_LINE_STRIP; break; case 3: mode = GL_LINE_LOOP; break; case 4: mode = GL_TRIANGLES; break; case 5: mode = GL_TRIANGLE_STRIP; break; case 6: mode = GL_TRIANGLE_FAN; break; case 7: mode = GL_QUADS; break; case 8: mode = GL_QUAD_STRIP; break; case 9: mode = GL_POLYGON; break; default: mode = GL_POINTS; break; } return;}//Setup GL in our SDL contextint initGL(GLvoid){ glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glEnableClientState(GL_VERTEX_ARRAY); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); return(TRUE);}//Draw our 8 points according to which ever mode is selectedint drawGLScene(GLvoid){ static GLint T0 = 0; static GLint Frames = 0;// Vertex array to contain 8 points static GLfloat vertices[] = { 0,0,-1, 1,0,-1, 1,1,-1, 0,1,-1, 0,0,0, 1,0,0, 1,1,0, 0,1,0 };//Array for drawing these 8 points static GLuint indices[] = { 0,1,2,3, 0,4,7,3, 3,7,6,2, 2,6,5,1, 1,0,4,5, 5,4,7,6 }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glVertexPointer(3, GL_FLOAT, 0, vertices); // Move back and rotate the cube continuously glTranslatef(0.0f,0.0f,-6.0f); glRotatef(yrot, 0.7, 1.0, 0.0); glDrawElements(mode, 24, GL_UNSIGNED_INT, indices); yrot += 0.5; SDL_GL_SwapBuffers();//Count frames per second Frames++; { GLint t = SDL_GetTicks(); if(t - T0 >= 5000) { GLfloat seconds = (t -T0)/1000.0; GLfloat fps = Frames/seconds; cout << Frames << " frames in " << seconds << " seconds = " << fps << " FPS." << endl; T0=t; Frames = 0; } } return(TRUE);}//Initialize it all and loop until we quitint main(int argc, char **argv){ int videoFlags; int done = FALSE; SDL_Event event; const SDL_VideoInfo *videoInfo; int isActive = TRUE; if(SDL_Init(SDL_INIT_VIDEO) < 0) { cout << "Video initialization failed: " << SDL_GetError() << endl; Quit(1); } videoInfo = SDL_GetVideoInfo(); if(!videoInfo) { cout << "Video query failed: " << SDL_GetError() << endl; Quit(1); } videoFlags = SDL_OPENGL; videoFlags |= SDL_GL_DOUBLEBUFFER; videoFlags |= SDL_HWPALETTE; videoFlags |= SDL_RESIZABLE; if(videoInfo->hw_available) videoFlags |= SDL_HWSURFACE; else videoFlags |= SDL_SWSURFACE; if(videoInfo->blit_hw) videoFlags |= SDL_HWACCEL; surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags); if(!surface) { cout << "Video mode set failed: " << SDL_GetError() << endl; Quit(1); } if(initGL() == FALSE) { cout << "Could not initialize OpenGL." << endl; Quit(1); } SDL_EnableKeyRepeat(200, 1); resizeWindow(SCREEN_WIDTH, SCREEN_HEIGHT); while(!done) { if(isActive) drawGLScene(); while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_ACTIVEEVENT: if(event.active.gain == 0) isActive = FALSE; else isActive = TRUE; break; case SDL_VIDEORESIZE: surface = SDL_SetVideoMode(event.resize.w, event.resize.h, 16, videoFlags); if(!surface) { cout << "Error while resizing window: " << SDL_GetError() << endl; Quit(1); } resizeWindow(event.resize.w, event.resize.h); break; case SDL_KEYDOWN: handleKeyPress(&event.key.keysym); break; case SDL_QUIT: done = TRUE; break; default: break; } } } Quit(0); return(0);}