OpenGL: Vertex arrays -> falsche Ausgabe
-
Hi,
ich habe folgendes Problem:Ich habe vier Dreiecke (zu zwei Vierecken zusammengesetzt). Alle haben eine Textur, zwei sind durchsichtig. Die Daten habe ich in einem Array des Typs folgender Klasse:
class CDLL cVertex3D { public: cVector2D texCoords; cColor color; cVector3D normal; cVector3D position; };Dabei ist cVector2D eine Klasse die 2 floats enthält (jeweils nichts anderes), cColor 4 floats und cVector3D 3 floats.
Dieses Array zeichne ich brute force:
cError cVideoDriver::DrawIndexedPrimitiveList(cPrimitiveType type, cVertex3D* vertices, uint vertexCount, uint* indices, uint primitiveCount) { if(vertices == NULL) { chaosLog.Write(CLL_DEBUG, string("cVideoDriver::DrawIndexedPrimitiveList()"), "NULL-Pointer: vertices"); return CE_NULL_POINTER; } if(indices == NULL) { chaosLog.Write(CLL_DEBUG, string("cVideoDriver::DrawIndexedPrimitiveList()"), "NULL-Pointer: indices"); return CE_NULL_POINTER; } int multiplier = 3; ´ if(type == CPT_QUAD) { glBegin(GL_QUADS); multiplier = 4; } else glBegin(GL_TRIANGLES); for(int i = 0; i < primitiveCount*multiplier; i++) { glTexCoord2f(vertices[indices[i]].texCoords.x, vertices[indices[i]].texCoords.y); glColor4f(vertices[indices[i]].color.r, vertices[indices[i]].color.g, vertices[indices[i]].color.b, vertices[indices[i]].color.a); glNormal3f(vertices[indices[i]].normal.x, vertices[indices[i]].normal.y, vertices[indices[i]].normal.z); glVertex3f(vertices[indices[i]].position.x, vertices[indices[i]].position.y, vertices[indices[i]].position.z); } glEnd(); return CE_NO_ERROR; }Das funktioniert alles wunderbar, ergibt alles die richtigen Bilder:
http://www.slin-online.de/brute_force.jpg.Wenn ich nun aber vertex arrays verwende:
cError cVideoDriver::DrawIndexedPrimitiveList(cPrimitiveType type, cVertex3D* vertices, uint vertexCount, uint* indices, uint primitiveCount) { if(vertices == NULL) { chaosLog.Write(CLL_DEBUG, string("cVideoDriver::DrawIndexedPrimitiveList()"), "NULL-Pointer: vertices"); return CE_NULL_POINTER; } if(indices == NULL) { chaosLog.Write(CLL_DEBUG, string("cVideoDriver::DrawIndexedPrimitiveList()"), "NULL-Pointer: indices"); return CE_NULL_POINTER; } glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY ); glEnableClientState(GL_NORMAL_ARRAY ); glTexCoordPointer(2, GL_FLOAT, sizeof(cVertex3D), &vertices[0].texCoords); glColorPointer(4, GL_FLOAT, sizeof(cVertex3D), &vertices[0].color); glNormalPointer(GL_FLOAT, sizeof(cVertex3D), &vertices[0].normal); glVertexPointer(3, GL_FLOAT, sizeof(cVertex3D), &vertices[0].position); if(type == CPT_QUAD) glDrawElements(GL_QUADS, primitiveCount * 4, GL_UNSIGNED_INT, indices); else glDrawElements(GL_TRIANGLES, primitiveCount * 3, GL_UNSIGNED_INT, indices); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY ); glDisableClientState(GL_NORMAL_ARRAY ); return CE_NO_ERROR; }ergibt das ganze folgendes Bild:
http://www.slin-online.de/vertex_array.jpgKann mir jemand einen Tipp geben warum da was schief läuft?
Sind meine Daten für OGL nicht zu gebrauchen? Dabei hab ich doch nur floats in den Klassen ö.ÖNun vielen Danke schonmal.
Tut mir leid für den vielen Code.MfG
-
Problem ist glaub ich das dein offset nicht stimmt! sagen wir mal du hast 4 byte... 2 willst du und 2 sind unerwünscht... also size=2 offset=2 nach 2 bytes bist du wieder dort wo du 2 liest.. beim lesen rückst du ja auch weiter... so würds zumindest ich verstehen... und es würe das sonderbare ergebniss erklären...
hoff ich konnte helfen
-
Ok das werd ich mal ausprobieren...
War mein Verdacht als ich das Tutorial dazu gelesen hab, aber irgendwie hatten die das im Beispiel so gemacht wie ich jetzt also hab ich net länger drüber nachgedacht... o.ODanke sehr

edit:
Ich fürchte das wars auch net...
Habs jetzt einfach so gemacht:glTexCoordPointer(2, GL_FLOAT, sizeof(cVertex3D)-sizeof(cVector2D), &vertices[0].texCoords); glColorPointer(4, GL_FLOAT, sizeof(cVertex3D)-sizeof(cColor), &vertices[0].color); glNormalPointer(GL_FLOAT, sizeof(cVertex3D)-sizeof(cVector3D), &vertices[0].normal); glVertexPointer(3, GL_FLOAT, sizeof(cVertex3D)-sizeof(cVector3D), &vertices[0].position);Nun wird nur noch jeweils ein dreieck der Quadrate angezeigt aber immernoch mit falscher Farbe usw...
Hat noch jemand eine Idee?