Ich bekomme eine EXC_BAD_ACCESS auf der glDrawElements() in diesem Code, aber nur, wenn der untere Block des Codes vorhanden ist. Ich denke, dass es etwas konzeptuelles sein muss, das ich vermisse, weil ich keine Nullzeiger oder andere Dinge finde, die diesen Fehler normalerweise verursachen können.Wie kann glDrawElements() beim Zeichnen mit Textur eine EXC_BAD_ACCESS verursachen?
glScalef(6, 6, 6);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3 ,GL_FLOAT, 0, model_verts);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, model_normals);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(num_tex_coords*2, GL_FLOAT, 0, tex_coords);
glDrawElements(GL_TRIANGLES, num_model_indices0, GL_UNSIGNED_SHORT, &model_indices0);
glDrawElements(GL_TRIANGLES, num_model_indices1, GL_UNSIGNED_SHORT, &model_indices1);
glDrawElements(GL_TRIANGLES, num_model_indices2, GL_UNSIGNED_SHORT, &model_indices2);
glDrawElements(GL_TRIANGLES, num_model_indices3, GL_UNSIGNED_SHORT, &model_indices3);
Dieser Code richtet meine Textur ein und scheitert nicht an irgendwelchen Zeilen.
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBlendFunc(GL_ONE, GL_SRC_COLOR);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
NSString *path = [[NSBundle mainBundle] pathForResource:@"booktex" ofType:@"jpg"];
NSData *texData = [[NSData alloc] initWithContentsOfFile:path];
UIImage *image = [[UIImage alloc] initWithData:texData];
if (image == nil)
NSLog(@"Do real error checking here");
GLuint width = CGImageGetWidth(image.CGImage);
GLuint height = CGImageGetHeight(image.CGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
imageData = malloc(height * width * 4);
context = CGBitmapContextCreate(imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextClearRect(context, CGRectMake(0, 0, width, height));
CGContextTranslateCTM(context, 0, height - height);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), image.CGImage);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
tex_coords kommen die Vt-Werte, die ich aus der OBJ-Datei analysiere. num_tex_coords ist eine Zählung dieser Zeilen, also multipliziere ich mit 2, um die Anzahl der Werte im Array zu erhalten. Ein Ausschnitt ist const float tex_coords [] [2] = { \t \t {0,25, 0,375}, \t \t {0,375, 0,25}, \t \t {0,25, 0,25}, \t \t {0,375, 0,25}, \t \t {0,25, 0,375}, \t \t {0,375, 0,375}, –