3D Modelle loader (OpenGL)
-
Hi, ich suche einen 3d Modelle loader in OpenGL,
den man über eine Include Datei linken kann.
Am besten ein loader für 3ds files.Mit "Modelle loader" meine ich eine Include Datei um das laden von 3D Modell Dateien zu vereinfachen!
Z.B.
Model1->Load("car.3ds"); Model->SetTexture(&Texture1); Model1->Draw();
Der Loader sollte auch Texturinformation laden!
MfG FB
-
Mit ein bißchen Modifikation kannst du die Examples einfach übernehmen
-
Hab ich schon versucht, aber bei mir funzt es nicht!
Ich benutze den Borland C++ Builder5Wie macht ihr das?
-
Es funzt jetzt einigermaßen!
Nur zeichnet er die Front Faces oder Back Faces nicht richtig!
Hab schon vieles probiert ( glEnable(GL_CULL_FACE) .... ).
Hier 2 Bilder des Fehlers:
Bild1: http://members.tripod.de/FrederikBoehm/1.bmp
Bild2: http://members.tripod.de/FrederikBoehm/2.bmpUnd hier das Programm:
http://members.tripod.de/FrederikBoehm/weiterleitung.html
-
Ohne den Source zu kennen:
Schalte Z-Testing ein!
-
-
Klappt auch nicht!
Hier der Quelletext:
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib") #pragma comment(lib, "glaux.lib") bool g_bFullScreen = true; // Set full screen as default HWND g_hWnd; // This is the handle for the window RECT g_rRect; // This holds the window dimensions HDC g_hDC; // General HDC - (handle to device context) HGLRC g_hRC; // General OpenGL_DC - Our Rendering Context for OpenGL HINSTANCE g_hInstance; #include "main.h" #include "Init.cpp" #include "3ds.h" #include "3ds.cpp" #include "t3de.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" #define FILE_NAME "face.3ds" TForm1 *Form1; CLoad3DS g_Load3ds; // This is 3DS class. This should go in a good model class. t3DModel g_3DModel; T3DEngine *E1; float A; int g_ViewMode = GL_TRIANGLES; UINT g_Texture[MAX_TEXTURES] = {0}; //Tex ID //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Application->OnIdle = IdleLoop; //glEnable(GL_TEXTURE_2D); // Enables Texture Mapping //glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { E1->Init(1.0,1.0,0.4,1.0,Handle); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1,1,-1,1,-100,100); glViewport(0,0,ClientWidth,ClientHeight); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); g_Load3ds.Import3DS(&g_3DModel, FILE_NAME); for(int i = 0; i < g_3DModel.numOfMaterials; i++) { // Check to see if there is a file name to load in this material if(strlen(g_3DModel.pMaterials[i].strFile) > 0) { // Use the name of the texture file to load the bitmap, with a texture ID (i). // We pass in our global texture array, the name of the texture, and an ID to reference it. CreateTexture(g_Texture, g_3DModel.pMaterials[i].strFile, i); //E1->LoadTexture(g_3DModel.pMaterials[i].strFile,i); } // Set the texture ID for this material g_3DModel.pMaterials[i].texureId = i; } glEnable(GL_LIGHT0); // Turn on a light with defaults set glEnable(GL_LIGHTING); // Turn on lighting glEnable(GL_COLOR_MATERIAL); //glEnable(GL_DEPTH_TEST); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormDestroy(TObject *Sender) { E1->Release(); } //--------------------------------------------------------------------------- void __fastcall TForm1::IdleLoop(TObject*, bool& done) { done = false; E1->SetupRC(Red,Green,Blue,Alpha); glRotated(0.01,0.0,1.0,0.0); glScaled(1.0,1.0,1.0); glDisable(GL_CULL_FACE); //gluLookAt( 0, 1.5f, 8, 0, 0.5f, 0, 0, 1, 0); for(int i = 0; i < g_3DModel.numOfObjects; i++) { // Make sure we have valid objects just in case. (size() is in the vector class) if(g_3DModel.pObject.size() <= 0) break; // Get the current object that we are displaying t3DObject *pObject = &g_3DModel.pObject[i]; // Check to see if this object has a texture map, if so bind the texture to it. if(pObject->bHasTexture) { // Turn on texture mapping and turn off color glEnable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); // Bind the texture map to the object by it's materialID glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]); } else { // Turn off texture mapping and turn on color glDisable(GL_TEXTURE_2D); // Reset the color to normal again glColor3ub(255, 255, 255); } // This determines if we are in wireframe or normal mode glBegin(g_ViewMode); // Begin drawing with our selected mode (triangles or lines) // Go through all of the faces (polygons) of the object and draw them for(int j = 0; j < pObject->numOfFaces; j++) { // Go through each corner of the triangle and draw it. for(int whichVertex = 0; whichVertex < 3; whichVertex++) { // Get the index for each point of the face int index = pObject->pFaces[j].vertIndex[whichVertex]; // Give OpenGL the normal for this vertex. glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z); // If the object has a texture associated with it, give it a texture coordinate. if(pObject->bHasTexture) { // Make sure there was a UVW map applied to the object or else it won't have tex coords. if(pObject->pTexVerts) { glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y); } } else { // Make sure there is a valid material/color assigned to this object. // You should always at least assign a material color to an object, // but just in case we want to check the size of the material list. // if the size is at least one, and the material ID != -1, // then we have a valid material. if(g_3DModel.pMaterials.size() && pObject->materialID >= 0) { // Get and set the color that the object is, since it must not have a texture BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color; // Assign the current color to this model glColor3ub(pColor[0], pColor[1], pColor[2]); } } // Pass in the current vertex of the object (Corner of current face) glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z); } } glEnd(); // End the drawing } SwapBuffers(hdc); }
E1 (T3DEngine) ist eine selbst geschriebene Include Datei, um das initallisieren von OpenGL zu vereinfachen!
-
Du hast nicht zufällig near und far-plane 83 Millionen Kilometer auseinander?
Bye, TGGC (Der Held ist zurück)
-
Warum?
MfG FB
-
weil dann das ganze sehr ungenau ist ...
bin ich blind oder legst du clipping planes überhaupt gar nicht an?
-
FB schrieb:
Warum?
MfG FB
Warum nicht?
Bye, TGGC (Der Held ist zurück)
-
Ich verstehe nicht was ihr damit meint!
Hier die clipping planes:
glOrtho(-1,1,-1,1,-100,100);
(oder verstehe ich das falsch?)
MfG FB
-
Sollte man für 3D-Darstellungen nicht eine perspektivische Projektion nehmen? Und keine orthografische Projektion.
PS: Ich kenne mich mit OpenGL nicht aus. Doch lässt der Funktionsname so einen Schluss zu.
cu
-
richtige schlussfolgerung
-
FB schrieb:
(oder verstehe ich das falsch?)
Toll, wenn du nichtmal deinen eigenen Code verstehst, ich les ihn ehh nicht. Wo sind denn nun die Clipping planes?
Bye, TGGC (Der Held ist zurück)
-
Und was wäher die perspektivische Projektion?
Habt ihr überhaubt den Effekt gesehen?
Hier 2 Bilder des Fehlers:
Bild1: http://members.tripod.de/FrederikBoehm/1.bmp
Bild2: http://members.tripod.de/FrederikBoehm/2.bmpUnd hier das Programm:
http://members.tripod.de/FrederikBoehm/weiterleitung.htmlTGGC schrieb:
Toll, wenn du nichtmal deinen eigenen Code verstehst, ich les ihn ehh nicht.
Is ja Nett!
Wenn ihr den Quelletext durchlesen würdet, währe ich euch sehr dankbar!
MfG FB
-
Schonmal was von einem Bilddateiformat namens "JPG" gehört?
-
Auf dem zweiten Bild sieht das nach einem Z-Buffer Problem aus. Kann auch am 3D Model liegen wenn diese zu "fein" erstellt wurde. Oder die near und far-plane liegen zu weit auseinander.
PS: Deinen Code wird keiner lesen. Wir können dich nur auf mögliche Fehler hinweisen.
-
FB schrieb:
Und was wäher die perspektivische Projektion?
schau dir mal glfrustrum oder gluperspective an....dort werden die clippingplanes eingestellt
-
Am 3D Modell wird es nicht liegen, da ich die Methode zum laden, aus dem Tutorial von www.gametutorials.com übernommen habe!
H.L.T.O schrieb:
Oder die near und far-plane liegen zu weit auseinander.
Ne! oder ist das etwa zu weit?: glOrtho(-1,1,-1,1,-1,100);
tomf schrieb:
schau dir mal glfrustrum oder gluperspective an.
glOrtho ist doch das selbe oder?
TomasRiker schrieb:
Schonmal was von einem Bilddateiformat namens "JPG" gehört?
Hab zur Zeit, wie du siehst echt größere Probleme!
Hier habt ihr die aktuelle Version zum downloaden (exe):
http://members.tripod.de/FrederikBoehm/weiterleitung.htmlMfG FB