Programas de prueba para opengl

En la clase de computacion gráfica probamos el siguiente codigo

#include
#include
#define EXIT_SUCCESS 0

void Dibuja(void);

int main(int argc, char **argv){

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("Ventana");
glutDisplayFunc(Dibuja);
glutMainLoop();
getchar();
return EXIT_SUCCESS;
}

void Dibuja(void){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

que usa opengl, por ahora no hace nada si no crear una ventana vacia, pero ella esta lista para desplegar figuritas, un ejemplo de como generar figuritas coloridas es el siguiente, no se asombre usté de la extension, es el precio de la naturaleza de glut:

/*
When creating your project, uncheck OWL,
uncheck Class Library, select Static
instead of Dynamic and change the target
model to Console from GUI.
Also link glut.lib to your project once its done.
*/

#include
// The GL Header File
#include
// The GL Utility Toolkit (Glut) Header

float rtri; // Angle For The Triangle
float rquad; // Angle For The Quad


void InitGL ( GLvoid ) // Create Some Everyday Functions
{

glShadeModel(GL_SMOOTH);
// Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
// Black Background
glClearDepth(1.0f);
// Depth Buffer Setup
glEnable(GL_DEPTH_TEST);
// Enables Depth Testing
glDepthFunc(GL_LEQUAL);
// The Type Of Depth Testing To Do
glEnable ( GL_COLOR_MATERIAL );
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}

void display ( void ) // Create The Display Function
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();
// Reset The Current Modelview Matrix
glPushMatrix();
glTranslatef(-1.5f,0.0f,-6.0f);
// Move Left 1.5 Units And Into The Screen 6.0
glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis
glBegin(GL_TRIANGLES);
// Drawing Using Triangles
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)
glColor3f(1.0f,0.0f,0.0f); // Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
glColor3f(0.0f,0.0f,1.0f); // Blue
glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
glColor3f(0.0f,1.0f,0.0f); // Green
glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
glEnd();
// Finished Drawing The Triangle

glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis
glColor3f(0.5f,0.5f,1.0f);
// Set The Color To Blue One Time Only
glBegin(GL_QUADS);
// Draw A Quad
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Blue
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back)
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back)
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
glEnd(); // Done
//Drawing The Quad

// Done Drawing The Quad
glPopMatrix();
rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW )
rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW )


glutSwapBuffers ( );
// Swap The Buffers To Not Be Left With A Clear Screen
}

void reshape ( int width , int height ) // Create The Reshape Function (the viewport)
{
if (height==0)
// Prevent A Divide By Zero By
{
height=1;
// Making Height Equal One
}

glViewport(0,0,width,height);
// Reset The Current Viewport

glMatrixMode(GL_PROJECTION);
// Select The Projection Matrix
glLoadIdentity();
// Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
// Select The Modelview Matrix
glLoadIdentity();
}

void keyboard ( unsigned char key, int x, int y ) // Create Keyboard Function
{
switch ( key ) {
case 27: // When Escape Is Pressed...
exit ( 0 ); // Exit The Program
break; // Ready For Next Case
default: // Now Wrap It Up
break;
}
}

void arrow_keys ( int a_keys, int x, int y ) // Create Special Function (required for arrow keys)
{
switch ( a_keys ) {
case GLUT_KEY_UP: // When Up Arrow Is Pressed...
glutFullScreen ( ); // Go Into Full Screen Mode
break;
case GLUT_KEY_DOWN: // When Down Arrow Is Pressed...
glutReshapeWindow ( 500, 500 ); // Go Into A 500 By 500 Window
break;
default:
break;
}
}


void main ( int argc, char** argv ) // Create Main Function For Bringing It All Together
{
glutInit ( &argc, argv ); // Erm Just Write It =)
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE ); // Display Mode
glutInitWindowSize ( 500, 500 ); // If glutFullScreen wasn't called this is the window size
glutCreateWindow ( "NeHe's OpenGL Framework" ); // Window Title (argv[0] for current directory as title)
glutFullScreen ( ); // Put Into Full Screen InitGL ();
glutDisplayFunc ( display ); // Matching Earlier Functions To Their Counterparts
glutReshapeFunc ( reshape );
glutKeyboardFunc ( keyboard );
glutSpecialFunc ( arrow_keys );
glutIdleFunc ( display );
glutMainLoop ( ); // Initialize The Main Loop
}


Para compilar este codigo en un sistema *nix necesitamos tener instalado freeglut toolkit o glut3g toolkit en el sistema, que no es si no el conjunto de librerias de glut. Para compilarlo, sin hacer uso de un makefile, por esta ocasion, diponemos de la siguiente linea de comando:

NOTESE QUEDEBEMOS TENER INSTALADA LA LIBRERIA GLUT, PARA ELLO POSTEE EN UNA ENTRADA ANTERIOR LOS PAQUETES NECESARIOS EN DEBIAN


gcc archivo_fuente -lglut -o archivo_salida

lo cual nos genera un archivo llamado archivo_salida, el cual ejecutamos en la terminal:

./archivo_salida (enter)

Makefile para openGL y Gtk+/wxWidgets

  • COMENZANDO POR EL PRINCIPIO
Tenemos que especificar que herramientas utilizaremos para desarrollar aplicaciones, me enfocare en las siguientes:

SO: Debian Lenny
OpenGL/Glut (version para linux freeglut3)
Make
Gcc/g++ (para programas escritos en C/C++)

instalamos esas dependencias:
sudo apt-get install gcc g++ make
sudo apt-get install freeglut3 freeglut3-dbg freeglut3-dev

Compilación de proyectos

MAKE
Dado el hecho de que debemos manejar librerías e incluso varios códigos fuente cuando programamos alguna aplicación, lo primero es entender como funcionan herramientas como el comando make, que ejecuta un script para realizar múltiples tareas.
basándonos en la información de la documentación oficial del proyecto GNU:

http://www.gnu.org/software/make/manual/make.html

realizamos la siguiente plantilla:

(no lo quería poner hasta que no entregara el previo de la practica 1 LOL)

#Makefile hecho por Yesica

OBJECTS = programa.o
OPENGL = -lglut
FUENTE = programa.c
SALIDA = programa.out
CC = gcc

inicio:
$(CC) $(FUENTE) $(OPENGL) -o $(SALIDA)

GA GA GA GA GA GA GA

Y AUN NO PARO DE REIR, GA GA GA GA GA GA!!!



Propuesta de trabajo

Je! bueno dado que este sem estaré bien metida en mi materia de compu gráfica, creo que mi trabajo será unificador, puesto que, el laboratorio lo tomaremos en el IBM JAVA de Estándares Abiertos, ubicado en posgrado, lugar en donde las maquinas trabajan con alguna versión de Fedora, por lo tanto, mi intención es echarle la mano al 99% de la clase que nunca ha programado nada en Linux, como? pues publicando código y ejemplos de como trabajar en un ambiente *nix, empezando por lo básico, Este rollo completo os podés leer aqui:

Cositas en red sobre seguridad en Linux

Baboseanto me encontre con un documento en la página de DGSCA que habla de las nociones básicas de seguridad en Linux, viene en un nivel básico-intermedio de conocimiento y nos recuerda aspectos que a veces no consideramos al hacer una instalación y que son buenas prácticas en pro de la seguridad. Aqui les dejo el link: