martes, 10 de abril de 2007

Previo Practica 5 Bitmap Mejorado version2

La version pasada no hace grande y chico el nombre esta si.


#include GL/glut.h
#include stdlib.h
#include stdio.h
#include windows.h
#include math.h

void text(GLuint x, GLuint y, char* format); //Pinta el nombre
void onMouse(int button, int state, int x, int y); //Eventos boton del mouse
void onMotion(int x, int y); //Evento de movimiento del mouse
GLint incrementa = 0;
float alpha, beta;
int xo, yo;
void init(void)
{
glClearColor (0.0, 0.0, 1.0, 0.0);
glShadeModel (GL_FLAT);
}
void text(GLuint x, GLuint y, char* format) {
va_list args;
char buffer[255], *p;
GLfloat font_scale = 119.05f + 33.33f;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, glutGet(GLUT_WINDOW_WIDTH), 0,
glutGet(GLUT_WINDOW_HEIGHT));
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glTranslatef(x, y, 0.0);
glRasterPos3f (90,180,0);
if(incrementa == 0)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *p);
if(incrementa == 1)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, *p);
if(incrementa == 2)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *p);
if(incrementa == 3)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p);
if(incrementa == 4)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *p);
if(incrementa == 5)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *p);
if(incrementa == 6)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p);
if(incrementa >=7)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p);
if(incrementa <= -1)
for(p = buffer; *p; p++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_10, *p);
//glRasterPos3f(500,0,0);
//glReadPixels(85,165,150,50,GL_RGB,GL_BITMAP,pix);
//glDrawPixels(150,50,GL_RGB,GL_BITMAP,pix);
//glColor3f(1.0,1.0,0.0);
//glBitmap (80,70,80, 180,10, 10,*p);
glPopAttrib();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
void onMouse(int button, int state, int x, int y)
{
if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {
incrementa++;
xo=x;
yo=y;
}
if ( (button == GLUT_RIGHT_BUTTON) & (state == GLUT_DOWN) ) {
incrementa--;
xo=x;
yo=y;
}
}
void onMotion(int x, int y) {
alpha = (alpha + (y - yo));
beta = (beta + (x - xo));
xo = x; yo = y;
glutPostRedisplay();
}
void display(void)
{
GLint command = 1;
glClear (GL_COLOR_BUFFER_BIT);
//glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); /* clear the matrix */
/* viewing transformation */
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
if (command) {
glColor3f(1.0,1.,0.0) ;
text(250,200, "%s", "aide");
}
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (0,0);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutMouseFunc(onMouse);
glutMotionFunc(onMotion);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

No hay comentarios: