PDA

View Full Version : OpenGL texture glTexCoord2d is not drawing



ricardoul
11-02-2017, 09:35 PM
Hello

I'm pretty new to opengl and c.

I'm having problems render a opengl texture.

I'm trying to load a texture from a png image The parser I'm using is from here https://github.com/DavidEGrayson/ahrs-visualizer/blob/master/png_texture.cpp

char str[]="bottom2.png";
GLuint image = png_texture_load(str, NULL, NULL);
And is returning a GLuint 61964157, so seems to be working.

So, my program has a method that go through the obj and put the vertex in the array depending on the type and get a counter of the size of the array



I'm having problems render a opengl texture.

I'm trying to load a texture from a png image The parser I'm using is from here https://github.com/DavidEGrayson/ahrs-visualizer/blob/master/png_texture.cpp

char str[]="bottom2.png";
GLuint image = png_texture_load(str, NULL, NULL);
And is returning a GLuint 61964157, so seems to be working.

So, my program has a method that go through the obj and put the vertex in the array depending on the type and get a counter of the size of the array

struct Vertice vertArrV[5000];
struct Vertice vertArrF[5000];
struct Vertice vertArrVT[5000];
struct Vertice vertArrVN[5000];

Then in my display mehod call all that opengl initializers, similar to also the same repo how the init things https://github.com/DavidEGrayson/ahrs-visualizer/blob/master/ahrs-visualizer.cpp#L339

Then in my display method, who is the one called by glutDisplayFunc


void display() { // Display function will draw the image.

glewInit();

glClearColor( 0, 0, 0, 1 ); // (In fact, this is the default.)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear buffers
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_TRIANGLES);
int i=0;
char str[]="bottom2.png";
GLuint image = png_texture_load(str, NULL, NULL);
if (image == 0 )
{
printf("\n error loading texture \n");
return;
}

glEnable(GL_TEXTURE_2D);
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//arrayCount[2] is number of faces
for(i;i<arrayCount[2];i++){
struct Vertice face =vertArrF[i];
struct Vertice verticeLoop1 =vertArrV[face.vert1];
struct Vertice verticeNormalLoop1 =vertArrVN[face.vertn1];
struct Vertice verticeTextureLoop1 =vertArrVT[face.vertt1];
struct Vertice verticeLoop2 =vertArrV[face.vert2];
struct Vertice verticeNormalLoop2 =vertArrVN[face.vertn2];
struct Vertice verticeTextureLoop2 =vertArrVT[face.vertt2];
struct Vertice verticeLoop3 =vertArrV[face.vert3];
struct Vertice verticeNormalLoop3 =vertArrVN[face.vertn3];
struct Vertice verticeTextureLoop3 =vertArrVT[face.vertt3];


glBegin(GL_TRIANGLES);
printf("%f %f %f",verticeTextureLoop1.x,verticeTextureLoop1.y,verti ceTextureLoop1.z);

glNormal3d( verticeNormalLoop1.x,verticeNormalLoop1.y,verticeN ormalLoop1.z);
glTexCoord2d(verticeTextureLoop1.x, verticeTextureLoop1.y);
glVertex3d( verticeLoop1.x,verticeLoop1.y,verticeLoop1.z);

glNormal3d( verticeNormalLoop2.x,verticeNormalLoop2.y,verticeN ormalLoop2.z);
glTexCoord2d(verticeTextureLoop2.x, verticeTextureLoop2.y);
glVertex3d( verticeLoop2.x,verticeLoop2.y,verticeLoop2.z);

glNormal3d( verticeNormalLoop3.x,verticeNormalLoop3.y,verticeN ormalLoop3.z);
glTexCoord2d(verticeTextureLoop3.x, verticeTextureLoop3.y);
glVertex3d( verticeLoop3.x,verticeLoop3.y,verticeLoop3.z);
glEnd();
glDisable(GL_TEXTURE_2D);

}

Also for debugging I put a printf on the texture vertex, and seems to be feeding the glTexCoord2d with the expected values

0.000000 0.000000 0.0000000.863281 0.218750 0.0000000.863281 0.218750 0.0000000.863281 0.218750 0.0000000.863281 0.039062 0.0000000.863281 0.218750 0.0000000.992188 0.039062 0.0000000.730469 0.472656 0.0000000.992188 0.527344 0.0000000.875000 0.328125 0.0000000.753906 0.453125 0.0000000.875000 0.328125 0.0000000.871094 0.441406 0.0000000.863281 0.210938 0.0000000.753906 0.453125 0.0000000.753906 0.453125 0.0000000.730469 0.417969 0.0000000.730469 0.417969 0.0000000.863281 0.218750 0.0000000.863281 0.000000 0.0000000.992188 0.277344 0.0000000.992188 0.410156 0.0000000.960938 0.554688 0.0000000.871094 0.441406 0.0000000.992188 0.277344 0.0000000.992188 0.410156 0.0000000.992188 0.093750 0.0000000.992188 0.148438 0.0000000.730469 0.472656 0.0000000.871094 0.441406 0.0000000.992188 0.148438 0.0000000.992188 0.410156 0.0000000.753906 0.527344 0.0000000.753906 0.453125 0.0000000.871094 0.441406 0.0000000.753906 0.527344 0.0000000.871094 0.441406 0.0000000.992188 0.527344 0.0000000.992188 0.148438 0.0000000.960938 0.550781 0.0000000.964844 0.554688 0.0000000.164062 0.308594 0.0000000.371094 0.250000 0.0000000.382812 0.273438 0.0000000.371094 0.550781 0.0000000.218750 0.550781 0.0000000.371094 0.250000 0.0000000.382812 0.273438 0.0000000.164062 0.308594 0.0000000.960938 0.550781 0.0000000.371094 0.292969 0.0000000.382812 0.273438 0.0000000.960938 0.550781 0.0000000.960938 0.550781 0.0000000.960938 0.550781 0.0000000.960938 0.550781 0.0000000.164062 0.000000 0.0000000.175781 0.023438 0.0000000.164062 0.000000 0.0000000.175781 0.023438 0.0000000.355469 0.000000 0.0000000.355469 0.019531 0.0000000.410156 0.339844 0.0000000.175781 0.339844 0.0000000.355469 0.000000 0.0000000.355469 0.019531 0.0000000.246094 0.101562 0.0000000.246094 0.101562 0.0000000.355469 0.019531 0.0000000.378906 0.062500 0.0000000.210938 0.375000 0.0000000.382812 0.375000 0.0000000.355469 0.019531 0.0000000.378906 0.062500 0.0000000.003906 0.214844 0.0000000.003906 0.214844 0.0000000.386719 0.132812 0.0000000.378906 0.062500 0.0000000.210938 0.417969 0.0000000.386719 0.417969 0.0000000.386719 0.132812 0.0000000.378906 0.062500 0.0000000.191406 0.222656 0.0000000.191406 0.222656 0.0000000.347656 0.203125 0.0000000.386719 0.132812 0.0000000.218750 0.476562 0.0000000.378906 0.476562 0.0000000.347656 0.203125 0.0000000.386719 0.132812 0.0000000.164062 0.308594 0.0000000.164062 0.253906 0.0000000.347656 0.203125 0.0000000.371094 0.250000 0.0000000.222656 0.515625 0.0000000.375000 0.515625 0.0000000.347656 0.203125 0.0000000.371094 0.250000 0.0000000.003906 0.386719 0.0000000.371094 0.292969 0.0000000.382812 0.273438 0.0000000.003906 0.386719 0.0000000.371094 0.578125 0.0000000.218750 0.578125 0.0000000.003906 0.386719 0.0000000.003906 0.386719 0.0000000.003906 0.253906 0.0000000.003906 0.253906 0.0000000.003906 0.066406 0.0000000.003906 0.066406 0.0000000.363281 0.605469 0.0000000.226562 0.605469 0.0000000.164062 0.386719 0.0000000.320312 0.957031 0.0000000.265625 0.957031 0.0000000.226562 0.957031 0.0000000.226562 0.992188 0.0000000.410156 0.957031 0.0000000.386719 0.957031 0.0000000.386719 0.957031 0.0000000.386719 0.992188 0.0000000.363281 0.957031 0.0000000.320312 0.957031 0.0000000.960938 0.554688 0.0000000.964844 0.554688 0.0000000.960938 0.550781 0.0000000.015625 0.570312 0.0000000.082031 0.570312 0.0000000.363281 0.871094 0.0000000.328125 0.871094 0.0000000.257812 0.871094 0.0000000.328125 0.871094 0.0000000.226562 0.871094 0.0000000.226562 0.933594 0.0000000.460938 0.957031 0.0000000.437500 0.957031 0.0000000.437500 0.957031 0.0000000.437500 0.992188 0.0000000.449219 0.914062 0.0000000.386719 0.957031 0.0000000.386719 0.933594 0.0000000.410156 0.933594 0.0000000.386719 0.933594 0.0000000.074219 0.527344 0.0000000.226562 0.933594 0.0000000.226562 0.957031 0.0000000.328125 0.933594 0.0000000.257812 0.933594 0.0000000.363281 0.933594 0.0000000.328125 0.933594 0.0000000.460938 0.957031 0.0000000.480469 0.957031 0.0000000.265625 0.832031 0.0000000.265625 0.832031 0.0000000.328125 0.871094 0.0000000.449219 0.914062 0.0000000.449219 0.914062 0.0000000.015625 0.570312 0.0000000.320312 0.832031 0.0000000.156250 0.515625 0.0000000.167969 0.484375 0.0000000.210938 0.511719 0.0000000.128906 0.515625 0.0000000.960938 0.550781 0.0000000.964844 0.554688 0.0000000.109375 0.484375 0.0000000.121094 0.585938 0.0000000.128906 0.515625 0.0000000.148438 0.457031 0.0000000.148438 0.457031 0.0000000.156250 0.414062 0.0000000.156250 0.515625 0.0000000.156250 0.414062


https://i.stack.imgur.com/IfjHV.png

OpenGL Call Stack


1: CGLChoosePixelFormat({kCGLPFAAllowOfflineRenderers }, 0x7f9627e0bb90, 2);
2: CGLCreateContext(0x7f9627e0bb90, 0x00000000, 0x7f962803a400);
3: glDrawBuffer(GL_FRONT);
4: glReadBuffer(GL_FRONT);
5: CGLSetParameter(0x7f962803a400, kCGLCPSwapInterval, {1});
6: CGLSetSurface(0x7f962803a400, {100, 78, 500, 522}, {0, 22, 500, 500});
7: glScissor(0, 0, 500, 500);
8: glViewport(0, 0, 500, 500);
9: CGLQueryRendererInfo(4294967295, 0x00000000, -1059176193);
10: CGLDestroyRendererInfo(0x7f9627f239a0);
11: glViewport(0, 0, 500, 500);
12: glGetString(GL_VERSION);
13: glGetString(GL_EXTENSIONS);
14: glClearColor(0, 0, 0, 1);
15: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
16: glEnable(GL_BLEND);
17: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
18: glEnable(GL_TEXTURE_2D);
19: glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
20: glClear(GL_COLOR_BUFFER_BIT);
21: glBegin(GL_TRIANGLES);
22: glGenTextures(1, 0x7fff52a8ba28);
23: glBindTexture(GL_TEXTURE_2D, 268344856);
24: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, 0x1127c9000);
25: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
26: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
27: glEnable(GL_TEXTURE_2D);
28: glClearColor(1, 1, 1, 0);
29: glMatrixMode(GL_PROJECTION);
30: glLoadIdentity();
31: glBegin(GL_TRIANGLES);
32: glNormal3d(0, 0, 0);
33: glTexCoord2d(0, 0);
34: glVertex3d(0, 0, 0);
35: glNormal3d(0, 0, 0);
36: glTexCoord2d(0, 0);
37: glVertex3d(0, 0, 0);
38: glNormal3d(0, 0, 0);
39: glTexCoord2d(0, 0);
40: glVertex3d(0, 0, 0);
41: glEnd();
42: glDisable(GL_TEXTURE_2D);
43: glBegin(GL_TRIANGLES);
44: glNormal3d(0.425325, -0.688191, 0.587785);
45: glTexCoord2d(0.863281, 0.21875);
46: glVertex3d(3.10864, -5.70501, 24.0788);
47: glNormal3d(1, 0, 0);
48: glTexCoord2d(0.730469, 0.257812);
49: glVertex3d(4.60787, -3.71942, 22.2232);
50: glNormal3d(0.262866, -0.951056, -0.16246);
51: glTexCoord2d(0.875, 0.328125);
52: glVertex3d(2.9837, -5.82911, 20.78);
53: glEnd();

Thanks in advance

P.D: Also asked it in SO (https://stackoverflow.com/questions/47086836/opengl-texture-gltexcoord2d-is-not-drawing), but no get much response

Dark Photon
11-03-2017, 06:57 AM
You've got a number of problems with your GL call stream. For starters, Check for GL Errors (https://www.khronos.org/opengl/wiki/GL_Error_Codes) and resolve the problems OpenGL points out to you. Some of the problems I see right off the bat: mismatched glBegin/glEnd calls, doing things besides registering vertex data between glBegin/glEnd pairs, etc.

Also realize that glBegin()/glEnd() is the legacy, inefficient method of registering vertex data in OpenGL. It's easy to get started on, but for efficiency you should plan to move on to using vertex arrays soon.

ricardoul
11-03-2017, 11:01 AM
I have done some changes to my void display reflecting your comments, not sure how to debug further the GL_INVALID_OPERATION, becouse seems to only be happening on the first call

About to moving to array vertex, yes I should do that, but first would be nice to make that work.


void display() { // Display function will draw the image.

glewInit();

glClearColor( 0, 0, 0, 1 ); // (In fact, this is the default.)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear buffers
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClear( GL_COLOR_BUFFER_BIT );
glBegin(GL_TRIANGLES);

int i=1;
char str[]="knight.png";
GLuint image = png_texture_load(str, NULL, NULL);

if (image == 0 )
{
printf("\n error loading texture \n");
return;
}

glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();


for(i;i<arrayCount[2];i++){
struct Vertice face =vertArrF[i];
struct Vertice verticeLoop1 =vertArrV[face.vert1];
struct Vertice verticeNormalLoop1 =vertArrVN[face.vertn1];
struct Vertice verticeTextureLoop1 =vertArrVT[face.vertt1];
struct Vertice verticeLoop2 =vertArrV[face.vert2];
struct Vertice verticeNormalLoop2 =vertArrVN[face.vertn2];
struct Vertice verticeTextureLoop2 =vertArrVT[face.vertt2];
struct Vertice verticeLoop3 =vertArrV[face.vert3];
struct Vertice verticeNormalLoop3 =vertArrVN[face.vertn3];
struct Vertice verticeTextureLoop3 =vertArrVT[face.vertt3];


glEnable(GL_TEXTURE_2D);
glBegin(GL_TRIANGLES);
glNormal3d( verticeNormalLoop1.x,verticeNormalLoop1.y,verticeN ormalLoop1.z);
glTexCoord2d(verticeTextureLoop1.x, verticeTextureLoop1.y);
glVertex3d( verticeLoop1.x,verticeLoop1.y,verticeLoop1.z);


glNormal3d( verticeNormalLoop2.x,verticeNormalLoop2.y,verticeN ormalLoop2.z);
glTexCoord2d(verticeTextureLoop2.x, verticeTextureLoop2.y);
glVertex3d( verticeLoop2.x,verticeLoop2.y,verticeLoop2.z);

glNormal3d( verticeNormalLoop3.x,verticeNormalLoop3.y,verticeN ormalLoop3.z);
glTexCoord2d(verticeTextureLoop3.x, verticeTextureLoop3.y);
glVertex3d( verticeLoop3.x,verticeLoop3.y,verticeLoop3.z);
glEnd();
glDisable(GL_TEXTURE_2D);
GLenum err = glGetError();
while (err != GL_NO_ERROR) {
printf("%f %f %f\n ",verticeNormalLoop1.x,verticeNormalLoop1.y);
printf("%f %f %f\n ",verticeNormalLoop2.x,verticeNormalLoop2.y);
printf("%f %f %f\n ",verticeNormalLoop3.x,verticeNormalLoop3.y);
printf("%f %f %f\n ",verticeLoop1.x,verticeLoop1.y);
printf("%f %f %f\n ",verticeLoop2.x,verticeLoop2.y);
printf("%f %f %f\n ",verticeLoop3.x,verticeNormalLoop3.y);
printf("%f %f %f\n ",verticeTextureLoop1.x,verticeTextureLoop1.y);
printf("%f %f %f\n ",verticeTextureLoop2.x,verticeTextureLoop2.y);
printf("%f %f %f\n ",verticeTextureLoop3.x,verticeTextureLoop3.y);
printf("error ");
printf("%s\n %d \n",GetGLErrorString(err), i);
err = glGetError();
}

}

glScalef(0.02,0.02,0.02);
glRotatef(45,1,1,0);


glutSwapBuffers(); // Required to copy color buffer onto the screen.

}

The new opengl trace only shows a GL_INVALID_OPERATION for the first vertex only, is pretty strange.



1: CGLChoosePixelFormat({kCGLPFAAllowOfflineRenderers }, 0x7fa96fd10c10, 2);
2: CGLCreateContext(0x7fa96fd10c10, 0x00000000, 0x7fa971007600);
3: glDrawBuffer(GL_FRONT);
4: glReadBuffer(GL_FRONT);
5: CGLSetParameter(0x7fa971007600, kCGLCPSwapInterval, {1});
6: CGLSetSurface(0x7fa971007600, {100, 78, 500, 522}, {0, 22, 500, 500});
7: glScissor(0, 0, 500, 500);
8: glViewport(0, 0, 500, 500);
9: CGLQueryRendererInfo(4294967295, 0x00000000, -1059176193);
10: CGLDestroyRendererInfo(0x7fa96fd46710);
11: glViewport(0, 0, 500, 500);
12: glGetString(GL_VERSION);
13: glGetString(GL_EXTENSIONS);
14: glClearColor(0, 0, 0, 1);
15: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
16: glEnable(GL_BLEND);
17: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
18: glEnable(GL_TEXTURE_2D);
19: glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
20: glClear(GL_COLOR_BUFFER_BIT);
21: glBegin(GL_TRIANGLES);
22: glGenTextures(1, 0x7fff59a00a08);
23: glBindTexture(GL_TEXTURE_2D, 152813080);
24: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, 0x10b856000);
25: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
26: glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
27: glClearColor(1, 1, 1, 0);
28: glMatrixMode(GL_PROJECTION);
29: glLoadIdentity();
30: glEnable(GL_TEXTURE_2D);
31: glBegin(GL_TRIANGLES);
32: glNormal3d(0.525731, 0.850651, 0);
33: glTexCoord2d(0.730469, 0.257812);
34: glVertex3d(3.48344, -1.48562, 24.4911);
35: glNormal3d(-0.525731, 0.850651, 0);
36: glTexCoord2d(0.992188, 0.277344);
37: glVertex3d(3.73332, -1.23742, 20.78);
38: glNormal3d(0.262866, -0.951056, -0.16246);
39: glTexCoord2d(0.875, 0.328125);
40: glVertex3d(4.60787, -3.71942, 22.2232);
41: glEnd();
42: glDisable(GL_TEXTURE_2D);
43: glGetError(); returns: GL_INVALID_OPERATION
44: glGetError(); returns: GL_NO_ERROR
45: glEnable(GL_TEXTURE_2D);
46: glBegin(GL_TRIANGLES);
47: glNormal3d(0.525731, 0.850651, 0);
48: glTexCoord2d(0.730469, 0.257812);
49: glVertex3d(3.48344, -1.48562, 24.4911);
50: glNormal3d(-0.587785, 0.425325, 0.688191);
51: glTexCoord2d(0.863281, 0.039062);
52: glVertex3d(-1.76387, -0.741022, 22.2232);
53: glNormal3d(-0.525731, 0.850651, 0);
54: glTexCoord2d(0.992188, 0.277344);
55: glVertex3d(3.73332, -1.23742, 20.78);
56: glEnd();
57: glDisable(GL_TEXTURE_2D);
58: glGetError(); returns: GL_NO_ERROR
59: glEnable(GL_TEXTURE_2D);
60: glBegin(GL_TRIANGLES);
61: glNormal3d(-0.850651, -0.525731, 0);
62: glTexCoord2d(0.992188, 0.09375);
63: glVertex3d(-1.26412, -1.48562, 24.4911);
64: glNormal3d(-0.442863, -0.238856, 0.864188);
65: glTexCoord2d(0.863281, 0.09375);
66: glVertex3d(-2.38855, -4.58812, 22.0171);
67: glNormal3d(-0.587785, 0.425325, 0.688191);
68: glTexCoord2d(0.992188, 0.039062);
69: glVertex3d(-1.76387, -0.741022, 22.2232);
70: glEnd();
71: glDisable(GL_TEXTURE_2D);
72: glGetError(); returns: GL_NO_ERROR
73: glEnable(GL_TEXTURE_2D);
74: glBegin(GL_TRIANGLES);
75: glNormal3d(1, 0, 0);
76: glTexCoord2d(0.730469, 0.257812);
77: glVertex3d(3.10864, -5.70501, 24.0788);
78: glNormal3d(0.587785, 0.425325, 0.688191);
79: glTexCoord2d(0.992188, 0.277344);
80: glVertex3d(2.9837, -5.82911, 20.78);
81: glNormal3d(-0.442863, -0.238856, 0.864188);
82: glTexCoord2d(0.863281, 0.039062);
83: glVertex3d(-2.38855, -4.58812, 22.0171);
84: glEnd();
85: glDisable(GL_TEXTURE_2D);
86: glGetError(); returns: GL_NO_ERROR
87: glEnable(GL_TEXTURE_2D);
88: glBegin(GL_TRIANGLES);
89: glNormal3d(0.295242, 0, -0.955423);
90: glTexCoord2d(0.863281, 0);
91: glVertex3d(-1.63893, -4.09171, 24.4911);
92: glNormal3d(-0.850651, -0.525731, 0);
93: glTexCoord2d(0.992188, 0.09375);
94: glVertex3d(-1.26412, -1.48562, 24.4911);
95: glNormal3d(0.525731, 0.850651, 0);
96: glTexCoord2d(0.730469, 0.472656);
97: glVertex3d(3.48344, -1.48562, 24.4911);
98: glEnd();
99: glDisable(GL_TEXTURE_2D);
100: glGetError(); returns: GL_NO_ERROR

arekkusu
11-03-2017, 01:54 PM
not sure how to debug further the GL_INVALID_OPERATION

Generally, use the "Break on Error" (https://developer.apple.com/library/content/technotes/tn2178/_index.html) checkbox.
Errors inside glBegin are a special case, though. You need to audit your usage of glBegin, and understand what is not legal.




15: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Your pixel format didn't request a depth buffer.




20: glClear(GL_COLOR_BUFFER_BIT);

Again?




21: glBegin(GL_TRIANGLES);
22: glGenTextures(1, 0x7fff59a00a08);

There's your problem, a Begin without End. Most commands other than vertex specification aren't allowed inside Begin. Including glGetError, so the error generated by glGenTextures can't be detected until End.