hola a todos, estoy practicando con PushMatrix y PopMatrix y por alguna razon no me funciona bien y me he quedado estancado.
Se supone que tendrian que salir dos triangulos
¿Alguien me puede dar una pista?
gracias
#include < windows.h >
#include < GL\gl.h >
#include < GL\glu.h >
#include < GL\glut.h >
void init( void )
{
glClearColor( 0.0 , 0.0 , 0.0 , 0.0 );
glEnable( GL_DEPTH_TEST );
glShadeModel( GL_SMOOTH );
glMatrixMode( GL_MODELVIEW );
gluLookAt( 0.5 , 0.5 , 8 , 0.5 , 0.5 , 0 , 0 , 1 , 0 );
}
void Keyboard( unsigned char key , int x , int y )
{
if ( key == 27 ) exit( 0 ) ;
}
void Redraw()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//primera figura
glPushMatrix();
glTranslatef( -3 , 0 , -16 );
glRotatef( -45 , 0 , 0 , 1 );
glBegin( GL_TRIANGLES );
glColor3f( 0.0 , 0.0 , 1.0 );glVertex3f( 0 , 0 , 0 );
glColor3f( 0.0 , 1.0 , 0.0 );glVertex3f( 1 , 0 , 0 );
glColor3f( 1.0 , 0.0 , 0.0 );glVertex3f( 0.5 , 1 , 0 );
glEnd;
glPopMatrix();
//segunda figura
glPushMatrix();
glTranslatef( 3 , 0 , -16 );
glRotatef( 45 , 0 , 0 , 1 );
glBegin( GL_TRIANGLES );
glColor3f( 0.0 , 0.0 , 1.0 );glVertex3f( 0 , 0 , 0 );
glColor3f( 0.0 , 1.0 , 0.0 );glVertex3f( 1 , 0 , 0 );
glColor3f( 1.0 , 0.0 , 0.0 );glVertex3f( 0.5 , 1 , 0 );
glEnd;
glPopMatrix();
glutSwapBuffers();
}
void Reshape( int anchura , int altura )
{
glViewport( 0 , 0 , ( GLsizei ) anchura , ( GLsizei ) altura );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 35 , ( anchura / altura ) , 0.1 , 10000 );
glMatrixMode( GL_MODELVIEW );
}
void main( int argc , char *argv[] )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize( 800 , 600 );
glutCreateWindow( "Tema2" );
init();
glutKeyboardFunc( Keyboard );
glutDisplayFunc( Redraw );
glutReshapeFunc( Reshape );
glutMainLoop();
}
En cambio si uso las funciones para crear primitivas si funciona
void Redraw()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glColor3f( 0.1 , 0.5 , 1.0 );
glTranslatef( 5 , 0 , 0 );
glutSolidSphere( 2 , 20 , 20 );
glPopMatrix();
glPushMatrix();
glColor3f( 0.8 , 0.5 , 0.1 );
glScalef( 1 , 2 , 1 );
glTranslatef( -1 , 0 , 0 );
glutSolidSphere( 2 , 20 , 20 );
glPopMatrix();
glutSwapBuffers();
}
Los transladas fuera de pantalla y con glutSphere y tal no... fijate bien.
Depende de la perspectiva y tal pero tiene pinta de eso no ?
Lo he probado y no quedan fuera si comento uno y luego el otro, ademas otra cosa si quiero hacer una animacion, tampoco funciona
añado esta linea al main
glGlutIdleFunc(animate);
y esta funcion
void animate()
{
glRotatef( 1 , 0 , 1 , 0 );
glutPostRedisplay();
Sleep( 100 );
}
y solo queda girado una vez[/code]
Porque idle es cuando no se está usando la ventana, sino recuerdo mal.
idle = desocupado, inactivo, inerte
lo que yo no entiendo es por que Visual Studio deja compilar con glEnd en vez de glEnd()
ponle los paréntesis y disfruta
:lol: :lol: :lol:
waaaaa!! gracias !! desdeluego ke ya me vale , tengo los ojos acartonaos de buscar por todos los lados , estaba ya pensado de comprar otro ordenador jajaja.
Y no te fijas en si tiene errores la aplicacion!? no se para ni te da ningún aviso el visual studio?!
Cita de: PromptY no te fijas en si tiene errores la aplicacion!? no se para ni te da ningún aviso el visual studio?!
visual studio no da ningún error ni warning con eso :P
PD: Otra cosa que va bien hacer cuando tienes errores es debuggarlo, que es lo que he hecho yo en el curro, y ver que esa linea se la sudaba, luego te fijas q le faltan los paréntesis :P
es que poner glEnd no es un error, es como poner 5, o si tienes una variable llamada pepito poner pepito;
Simplemente es inutil, pero no es un error.
Ahi esta la cosa , no me di cuenta principalmente porque no me daba ninguna clase de error , haber si poco a poco me voy habituando :)
He hecho una prueba rápida:
#include <iostream>
int myFuncion()
{
printf("holaaaa\n");
return 0;
}
int main()
{
myFuncion();
myFuncion;
return 0;
}
con Visual Studio:
Warning 1 warning C4551: function call missing argument list e:\sandbox\vs2005tests\bugone\bugone\main.cpp 14
desde debian:
main.cpp: In function int main():
main.cpp:13: warning: statement is a reference, not call, to function myFuncion