Programación Específica > OpenGL
Dibujado se sobrepone al anterior
Geo:
Qué tal, recién le estoy echando un vistazo a OpenGL, estoy checando unos ejemplos de la Superbiblia :).
Tengo un problema, el siguiente código:
--- Código: Text --- // Points.c// OpenGL SuperBible// Demonstrates OpenGL Primative GL_POINTS// Program by Richard S. Wright Jr. #include "../../shared/gltools.h" // OpenGL toolkit#include <math.h>#include <cstdio> // Define a constant for the value of PI#define GL_PI 3.1415f // Rotation amountsstatic GLfloat xRot = 0.0f;static GLfloat yRot = 0.0f; // Called to draw scenevoid RenderScene(void) { GLfloat x,y,z,angle; // Storeage for coordinat // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Call only once for all remaining points glBegin(GL_POINTS); z = -50.0f; for(angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.1f) { x = 50.0f*sin(angle); y = 50.0f*cos(angle); // Specify the point and move the Z value up a little glVertex3f(x, y, z); z += 0.5f; } // Done drawing points glEnd(); // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); } // This function does any needed initialization on the rendering// context. void SetupRC() { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); // Set drawing color to green glColor3f(0.0f, 1.0f, 0.0f); } void SpecialKeys(int key, int x, int y) { if(key == GLUT_KEY_UP) xRot-= 5.0f; if(key == GLUT_KEY_DOWN) xRot += 5.0f; if(key == GLUT_KEY_LEFT) yRot -= 5.0f; if(key == GLUT_KEY_RIGHT) yRot += 5.0f; if(key > 356.0f) xRot = 0.0f; if(key < -1.0f) xRot = 355.0f; if(key > 356.0f) yRot = 0.0f; if(key < -1.0f) yRot = 355.0f; // Refresh the Window glutPostRedisplay(); } void ChangeSize(int w, int h) { GLfloat nRange = 1000.0f; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("Points Example"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); SetupRC(); glutMainLoop(); return 0; } Dibuja unos puntos en espiral y permite mover la perspectiva con las flechas del teclado, lo probé hace algunas semanas, y funcionaba muy bien, pero hoy intento de nuevo y ahora al intentar mover, el dibujo anterior no se borra, sino que las nuevas posiciones se van sobreponiendo a las anteriores, quedando todo encimado tras intentar mover varias veces.
¿Alguien sabe si es posible modificar esto en código? Porque por ahora mi única idea es algo con drivers o versión de alguna librería, acabo de instalar la última versión de DirectX pero no sé si tenga algo que ver con esto.
Gracias de antemano por cualquier ayuda que puedan darme :).
su -:
--- Código: C --- void RenderScene(void) { // Limpiamos todos los pixeles glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLfloat x,y,z,angle; // Storeage for coordinat // Save matrix state and do the rotation glPushMatrix(); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); // Call only once for all remaining points glBegin(GL_POINTS); z = -50.0f; for(angle = 0.0f; angle <= (2.0f*GL_PI)*3.0f; angle += 0.1f) { x = 50.0f*sin(angle); y = 50.0f*cos(angle); // Specify the point and move the Z value up a little glVertex3f(x, y, z); z += 0.5f; } // Done drawing points glEnd(); // Restore transformations glPopMatrix(); // Flush drawing commands glutSwapBuffers(); } Sino funciona, ponlo en el SetupRC.
PD: Te recomiendo OpenGL Programming Guide editorial Addison-Wesley ;)
Geo:
Idi**a de mi, ahora mismo que probé en linux encontré el error :brickwall:.
Efectivamente, no estaba borrando :brickwall:. eso me pasa por creer ciegamente que el código estaba intacto desde la última vez que lo había visto funcionar :p.
su, muchas gracias por la ayuda, y también por la recomendación, cuando estaba por comprarme un libro para empezar a echarle un vistazo a OpenGL me decidí por el de la Superbiblia porque el que comentas lo tiene mi asesor, y se supone que me lo prestaría :P (mañana mismo se lo pido ;)).
Gracias :).
hdsk:
Hola,
El problema que tienen es porque antes de dibujar siempre tienen que hacer un glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Ustedes compilan en windows con MINGW y GLUT?, si saben como hacer eso please helpme :-)
Salu2
BlackWind:
Hola Geo,
Si no tienes inconveniente de trabajar en windows en lugar de linux, te recomendaria que lo hicieras sobre windows, ya que las actualizaciones de linux para opengl son malisimas, a veces genera muchos problemas (no lo digo por el problema que te paso, si no por otros)
saludos,
Navegación
[#] Página Siguiente
Ir a la versión completa