Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Fr Jul 18, 2025 04:17

Foren-Übersicht » Programmierung » OpenGL
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Falsche Texturdarstellung -.-
BeitragVerfasst: So Mai 24, 2009 18:30 
Offline
DGL Member

Registriert: Sa Mai 23, 2009 16:43
Beiträge: 1
Hallo bin Neu hier,

wir haben grad in der Schule ein Projekt am laufen, ein Kumpel und ich wollen das Sonnensystem in 3D abbilden mittels OpenGL.
Nun ich bin ein absoluter Neueinsteiger in OpenGL, naja nach 3 Tage Dauerprogrammieren und unendlich viel gelesenen Tutorials sind wir soweit, das wir 4 Planeten um die Sonne kreisen lassen, was unns auch sehr gefreut hat das dies gut geklappt hat.
Nun als wir den Jupiter darstellen wollten, wurde seine Textur verzerrt dargestellt (Nach unten hin in die Länge gezogen).
Wir haben absolut keine Ahnung warum.

Hier mein Code:


Code:
  1.  
  2. //---------------------------------------------------------------------------
  3. #ifdef _WIN32
  4. #include <windows.h>
  5. #define GLUT_BUILDING_LIB
  6. #include "GL/gl.h"
  7. #include "GL/glut.h"
  8. #include <vcl.h>
  9. #include <conio.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <math.h>
  13. #pragma argsused
  14. #define DELTA 0.25f
  15. #include "Berechnungen.h"
  16. Berechnung berechne1;
  17. GLfloat x1,y1;
  18. GLfloat x2,y2;
  19. GLfloat x3,y3;
  20. GLfloat x4,y4;
  21. GLfloat x5,y5;
  22. GLfloat x6,y6;
  23. GLfloat x7,y7;
  24.  
  25. GLfloat rotation1,rotation2;
  26. GLfloat rotation3,rotation4;
  27. GLfloat rotation5,rotation6;
  28. GLfloat rotation7,rotation8;
  29.  
  30. GLfloat zoomfaktor=1.0;
  31.  
  32.         GLfloat pos[5] =   {-1, 0, -2};
  33.         GLfloat white[4] = {1., 1., 1., 1.};
  34.         GLfloat black[4] = {0., 0., 0., 0.};
  35.  
  36.  
  37. GLUquadric *quadSphere, *quadSphere1,*quadSphere2;
  38.  
  39. // Funktion zum darstellen der Kugel
  40. void zeichne_kugel(void)
  41. {
  42.  
  43.  
  44.     glClear ( GL_DEPTH_BUFFER_BIT );
  45.     glClear ( GL_COLOR_BUFFER_BIT );
  46.     glPushMatrix();
  47.  
  48.     //"Sonne"
  49.     glMatrixMode(GL_MODELVIEW);
  50.     glLoadIdentity ();
  51.     glTranslatef (0,0, -2);
  52.     glRotatef (rotation2,0. , 0., 1.);
  53.     glLightfv (GL_LIGHT1, GL_POSITION, pos);  //Setze Position
  54.     glColor3f (1.0, 1.0, 0.0);
  55.     gluSphere (quadSphere1, .25, 50, 25);
  56.     rotation2=(rotation2-0.15);
  57.     glutPostRedisplay ();
  58.  
  59.     //"Erde=Fixpunkt"
  60.  
  61.     glMatrixMode(GL_MODELVIEW);
  62.     glLoadIdentity ();
  63.     glTranslatef (x1, y1, -2);
  64.     glRotatef (rotation1,0. , 1., 0.);
  65.     glColor3f (0., .4, 1.0);
  66.     gluSphere (quadSphere, 0.0228843, 100, 50);
  67.     rotation1=(rotation1+0.6);
  68.     x1 = berechne1.berechneNeuePosition_x1();
  69.     y1 = berechne1.berechneNeuePosition_y1();
  70.     glutPostRedisplay ();
  71.  
  72.     //"Merkur"
  73.  
  74.     glLoadIdentity ();
  75.     glTranslatef (x2, y2, -2);
  76.     glRotatef (rotation1,0. , 1., 0.);
  77.     glColor3f (.5, .5, .5);
  78.     gluSphere (quadSphere, 0.008764, 100, 50);
  79.     rotation1=(rotation1+0.6);
  80.     x2 = berechne1.berechneNeuePosition_x2();
  81.     y2 = berechne1.berechneNeuePosition_y2();
  82.     glutPostRedisplay ();
  83.  
  84.     //"Venus"
  85.  
  86.     glLoadIdentity ();
  87.     glTranslatef (x3, y3, -2);
  88.     glRotatef (rotation1,0. , 1., 0.);
  89.     glColor3f (.2, 1.2, 1.);
  90.     gluSphere (quadSphere, 0.02173157, 100, 50);
  91.     rotation1=(rotation1+0.6);
  92.     x3 = berechne1.berechneNeuePosition_x3();
  93.     y3 = berechne1.berechneNeuePosition_y3();
  94.     glutPostRedisplay ();
  95.  
  96.     //"Mars"
  97.  
  98.     glLoadIdentity ();
  99.     glTranslatef (x4, y4, -2);
  100.     glRotatef (rotation1,0. , 1., 0.);
  101.     glColor3f (1.0, .6, 0.);
  102.     gluSphere (quadSphere, 0.01221299463, 100, 50);
  103.     rotation1=(rotation1+0.6);
  104.     x4 = berechne1.berechneNeuePosition_x4();
  105.     y4 = berechne1.berechneNeuePosition_y4();
  106.     glutPostRedisplay ();
  107.  
  108.     //"Juptier"
  109.  
  110.     glLoadIdentity ();
  111.     glTranslatef (x5, y5, -2);
  112.     glRotatef (rotation1,0. , 1., 0.);
  113.     glColor3f (1.0, .6, 0.);
  114.     gluSphere (quadSphere2, 0.14, 100, 50);
  115.     rotation1=(rotation1+0.6);
  116.     x5 = berechne1.berechneNeuePosition_x5();
  117.     y5 = berechne1.berechneNeuePosition_y5();
  118.     glutPostRedisplay ();
  119.     glPopMatrix();
  120.  
  121.      glutSwapBuffers();
  122. }
  123.  
  124. void zeichne_bildNeu(int w, int h)
  125. {
  126.    glViewport (0,0, w, h);
  127.    glMatrixMode (GL_PROJECTION);
  128.    glLoadIdentity ();
  129.    gluPerspective (150, (float)w/(float)h, 2, 20.);
  130.    glMatrixMode (GL_MODELVIEW);
  131.    glLoadIdentity();
  132. }
  133.  
  134. void init (void)
  135. {
  136.      glEnable (GL_DEPTH_TEST);
  137.      {
  138.         glEnable (GL_LIGHTING);
  139.         glEnable (GL_LIGHT1);
  140.         glLightfv (GL_LIGHT1, GL_DIFFUSE, white);
  141.         glEnable (GL_COLOR_MATERIAL);
  142.      }
  143.  
  144.        quadSphere =  gluNewQuadric();
  145.        quadSphere1 = gluNewQuadric();
  146.        quadSphere2 = gluNewQuadric();
  147.  
  148.        glutDisplayFunc (zeichne_kugel);
  149.        glutReshapeFunc (zeichne_bildNeu);
  150. }
  151.  
  152. void main(int argc, char** argv)
  153. {
  154.  
  155.  
  156.     glutInit (&argc,argv);
  157.     glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
  158.  
  159.     glutInitWindowSize (500,500);
  160.     glutInitWindowPosition (0,0);
  161.     glutCreateWindow ("2Kugeln_Umkreisen");
  162.     glutIdleFunc(zeichne_kugel);
  163.     init();
  164.  
  165.  
  166.     rotation1 = berechne1.getRotation_1();
  167.     rotation2 = berechne1.getRotation_2();
  168.  
  169.     glutMainLoop ();
  170.  
  171.  
  172. }
  173.  
  174.  
  175.  
  176. #endif
  177.  
  178.  


---------------------------------------Klasse Berechnung----------------------------

Code:
  1.  
  2. #include "Berechnungen.h"
  3.  
  4.  
  5. float Berechnung::getx_1()
  6. {
  7.    x_1 = 0;
  8.    return x_1;
  9. };
  10.  
  11. float Berechnung::gety_1()
  12. {
  13.    y_1 = 0;
  14.    return y_1;
  15. };
  16.  
  17.  
  18. float Berechnung::getRotation_1()
  19. {
  20.    rotation_1=0;
  21.    return rotation_1;
  22. };
  23.  
  24. float Berechnung::getRotation_2()
  25. {
  26.    rotation_2=0;
  27.    return rotation_2;
  28. };
  29.  
  30. //Berechnung der Umkreisungsgeschwindikeit der Erde
  31. float Berechnung::berechneNeuePosition_x1()
  32. {
  33.       radius_1=1.25;
  34.       x_1 = radius_1*sin(winkel_1);
  35.       winkel_1=winkel_1+0.001;
  36.       return x_1;
  37. };
  38.  
  39. float Berechnung::berechneNeuePosition_y1()
  40. {
  41.     radius_1=1.25;
  42.     y_1 = radius_1*cos(winkel_1);
  43.     winkel_1=winkel_1+0.001;
  44.     return y_1;
  45. };
  46.  
  47. //Berechnung der Umkreisungsgeschwindigkeit des Merkur
  48. float Berechnung::berechneNeuePosition_x2()
  49. {
  50.       radius_2=0.5;
  51.       x_2 = radius_2*sin(winkel_2);
  52.       winkel_2=winkel_2+0.00416;
  53.       return x_2;
  54. };
  55.  
  56. float Berechnung::berechneNeuePosition_y2()
  57. {
  58.     radius_2=0.5;
  59.     y_2 = radius_2*cos(winkel_2);
  60.     winkel_2=winkel_2+0.00416;
  61.     return y_2;
  62. };
  63.  
  64. //Berechnung der Umkreisungsgeschwindigkeit der Venus
  65. float Berechnung::berechneNeuePosition_x3()
  66. {
  67.       radius_3=0.9;
  68.       x_3 = radius_3*sin(winkel_3);
  69.       winkel_3=winkel_3+0.00161;
  70.       return x_3;
  71. };
  72.  
  73. float Berechnung::berechneNeuePosition_y3()
  74. {
  75.     radius_3=0.9;
  76.     y_3 = radius_3*cos(winkel_3);
  77.     winkel_3=winkel_3+0.00161;
  78.     return y_3;
  79. };
  80.  
  81. //Berechnung der Umkreisungsgeschwindigkeit des Mars
  82. float Berechnung::berechneNeuePosition_x4()
  83. {
  84.       radius_4=1.896;
  85.       x_4 = radius_4*sin(winkel_4);
  86.       winkel_4=winkel_4+0.00053;
  87.       return x_4;
  88. };
  89.  
  90. float Berechnung::berechneNeuePosition_y4()
  91. {
  92.     radius_4=1.896;
  93.     y_4 = radius_4*cos(winkel_4);
  94.     winkel_4=winkel_4+0.00053;
  95.     return y_4;
  96. };
  97.  
  98. //Berechnung der Umkreisungsgeschwindikeit des Jupiters
  99. float Berechnung::berechneNeuePosition_x5()
  100. {
  101.       radius_5=4.5;
  102.       x_5 = radius_5*sin(winkel_5);
  103.       winkel_5=winkel_5+0.0000843;
  104.       return x_5;
  105. };
  106. float Berechnung::berechneNeuePosition_y5()
  107. {
  108.       radius_5=4.5;
  109.       y_5 = radius_5*cos(winkel_5);
  110.       winkel_5=winkel_5+0.0000843;
  111.       return y_5;
  112. }
  113.  
  114.  
  115.  


Vill sieht jmd. nen Bug, aber ich denke eher, das hat mit der gluPerspective(); zu tun das der Jupiter verzerrt wird.
(sieht aus wie ne umgedrehte Eistüte)
Beleuchtung bitte nicht beachten stimmt noch absolut nicht ;)

Codiert wurde alles im Borland C++ Builder 5 Standart Edition, und GLUT.


Vielen Dank schonmal,

mfg cenox[/img][/code]


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Mai 24, 2009 19:00 
Offline
DGL Member
Benutzeravatar

Registriert: Do Sep 02, 2004 19:42
Beiträge: 4158
Programmiersprache: FreePascal, C++
Ohne eine genaue Vorstellung zu haben, wie das bei dir aussieht (Screenshot?), würde ich vermuten, dass das mit dem Aufbau der GLU-Sphere zusammen hängt. Das ist eine UV-Sphäre (siehe Anhang). Durch die Form, speziell an der ober/unterkante, kommt es da gerne zu verzerrungen. Aber wie gesagt, ich bin mir nicht sicher, ob das überhaupt dein Problem ist. Wenn ja, schau mal nach Ico/Iso-Spheres ausschau.

Gruß Lord Horazont


Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.

_________________
If you find any deadlinks, please send me a notification – Wenn du tote Links findest, sende mir eine Benachrichtigung.
current projects: ManiacLab; aioxmpp
zombofant networkmy photostream
„Writing code is like writing poetry“ - source unknown


„Give a man a fish, and you feed him for a day. Teach a man to fish and you feed him for a lifetime. “ ~ A Chinese Proverb


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Mai 24, 2009 19:34 
Offline
DGL Member

Registriert: Fr Okt 03, 2008 13:32
Beiträge: 367
Ist die automatische Texturkoordinaten-Generierung an?
Im Wiki steht unter gluSphere das man die mit gluQuadricTexture einschalten kann.
Zumindest finde ich den Befehl bei dir nicht.

Ansonsten wäre ein Screenshot, wie schon gesagt, hilfreich.


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 3 Beiträge ] 
Foren-Übersicht » Programmierung » OpenGL


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 3 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.008s | 14 Queries | GZIP : On ]