viernes, 22 de octubre de 2010

Figuras basicas integradas en open GL




#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <gl.h>
#include <glu.h>
#include <glaux.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "GlAux.Lib")
#pragma comment(lib, "glu32.lib")

void main(int i, char** argv)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
auxInitPosition (0, 0, 600,400);
auxInitWindow (argv[0]);

glClearColor(1.0,0.0,1.0,0.4);
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);
glVertex2f(-0.2,-0.1);
glVertex2f(-0.2,0.5);
glVertex2f(0.2,0.5);
glColor3f(1.0f, 1.0f, 1.0f);
glVertex2f(0.2,-0.1);
glEnd();

glShadeModel(GL_SMOOTH);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f,0.0f);
glVertex2f(0.0f, 0.6f);
glColor3f(0.0f,1.0f,0.0f);
glVertex2f(0.3f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(-0.3f, 0.0f);
glEnd();

glShadeModel(GL_SMOOTH);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex2f(0.0f, 0.0f);
glColor3f(0.0f,1.0f, 0.0f);
glVertex2f(-0.15f, 0.3f);
//glColor3f(0.0f, 0.0f, 1.0f);
glVertex2f(0.15f, 0.3f);
glEnd();


glEnable(GL_LINE_STIPPLE);
glLineStipple(1,0x0C0F);
glBegin(GL_LINES);
glColor3f(0.0,1.0,0.0);
glVertex2f(-0.35f,-0.05f);
glVertex2f(0.0f, 0.65f);
// glColor3f(0.0,0.2,0.5);
glVertex2f(0.0f, 0.65f);
// glColor3f(0.3,-0.3,0.6);
glVertex2f(0.35f, -0.05f);
glVertex2f(0.35f, -0.05f);
glVertex2f(-0.35f, -0.05f);
glDisable(GL_LINE_STIPPLE);
glEnd();


glPointSize (10); //Tamaño del punto
glColor3f(1.0,1.0,1.1);
glBegin(GL_POINTS);
glVertex3f(0.0f, 0.175f, 0.0f);
glEnd();

glPointSize (6); //Tamaño del punto
glColor3f(1.0,1.0,1.1);
glBegin(GL_POINTS);
glVertex3f(-0.15f, 0.125f, 0.0f);
glEnd();

glPointSize (6); //Tamaño del punto
glColor3f(1.0,1.0,1.1);
glBegin(GL_POINTS);
glVertex3f(0.15f, 0.125f, 0.0f);
glEnd();

glPointSize (6); //Tamaño del punto
glColor3f(1.0,1.0,1.1);
glBegin(GL_POINTS);
glVertex3f(0.0f, 0.415f, 0.0f);
glEnd();
glFlush();
getchar();
}



#include "stdafx.h"

#include < conio.h>
#include < windows.h>
#include < stdio.h>
#include < math.h>
#include < gl.h>
#include < glu.h>
#include < glaux.h>

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "GlAux.Lib")
#pragma comment(lib, "glu32.lib")

void main(int i,char** argv)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
auxInitPosition (250, 10, 700,700);
auxInitWindow (argv[0]);
GLfloat angulo;

glClearColor(0.0,0.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
int k=0;

glBegin(GL_LINES);

for (i=0; i< 360; i+=3)
{
k++;
angulo = (GLfloat)i*3.14159f/180.0f;


glVertex3f(0.3f, 0.3f, 0.0f);
if(k==2)
{
k=0;
glColor3f(1.0f, 1.0f, 0.0f);

}
else
{glColor3f(0.0f, 1.0f,0.0f);}
glVertex3f(cos(angulo), sin(angulo), 0.0f);
}
glEnd();

glEnable(GL_LINE_STIPPLE);
glLineStipple(6,0x5555);
glLineWidth(3.0f);

glBegin(GL_LINES);
glLineStipple (5,0x5555); //Patron de la linea
glColor3f(1.0f, 1.0f, 0.0f);
glLineWidth(0.3f);
glLineStipple(5,0x5555);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(0.0f, 1.0f);
glVertex2f(0.0f, -1.0f);
glEnd();


glFlush();
getchar();

}





#include "stdafx.h"

#include <conio.h>
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include <gl.h>
#include <glu.h>
#include <glaux.h>


#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "GlAux.Lib")
#pragma comment(lib, "glu32.lib")

void main(int i,char** argv)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGBA);
auxInitPosition (0, 0, 600,400);
auxInitWindow (argv[0]);
glClearColor(1.0,1.0,1.0,0.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glTranslatef(0.0f,0.6f,-0.8);
glMatrixMode(GL_MODELVIEW);
glRotatef(30.0f,0.4f,0.5f,0.4f);


gluPerspective(40.0,1.0,1.0,1.0);

glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glColor3f(1.0f, 1.0f, 0.0f);

glBegin(GL_QUADS); //cara frontal

glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glEnd();

glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS); //cara trasera
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glEnd();

glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS); //cara lateral izq
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();

glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS); //cara lateral dcha
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glEnd();

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glColor4f(1.0f,1.0f,0.0f,0.9f);
//glColor3f(1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS); //cara arriba
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, 0.5f);
glVertex3f( 0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glEnd();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glColor4f(0.0f,1.0f,1.0f,0.1f);
//nhjm,glColor3f(1.0f, 0.0f, 4.0f);
glBegin(GL_QUADS); //cara abajo
glVertex3f( 0.5f, -0.5f, -0.5f);
glVertex3f( 0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glEnd();



glEnable(GL_LINE_STIPPLE);
glLineStipple(6,0x5555);
glLineWidth(3.0f);

glBegin(GL_LINES);
glLineStipple (5,0xAAAA);
glColor3f(1.0f, 0.0f, 1.0f);
glLineWidth(0.3f);
glLineStipple(5,0x5555);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glVertex2f(0.0f, 1.0f);
glVertex2f(0.0f, -1.0f);
glEnd();

glFlush();
getchar();
}