This is probably a silly mistake but I cant see it?! I have classes defining geometry and classes that render that geometry. Right now it is basic triangles and colours for each vertex.
Here is the code defining said geometry objects data:
CGeometry* g = new CGeometry(); g->vertexes = new double[3*3]; g->vertexes[0] = 0; g->vertexes[1] = 0; g->vertexes[2] = 0; g->vertexes[3] = 100; g->vertexes[4] = 100; g->vertexes[5] = 0; g->vertexes[6] = 100; g->vertexes[7] = 0; g->vertexes[8] = 0; g->colors = new double[12]; g->colors[0] = 1; g->colors[1] = 1; g->colors[2] = 0; g->colors[3] = 1; g->colors[4] = 1; g->colors[5] = 0; g->colors[6] = 1; g->colors[7] = 0; g->colors[8] = 0; g->colors[9] = 1; g->colors[10] = 1; g->colors[11] = 0;
And here is the code that renders said data:
CGeometry* g = object->geometry; int j = object->endIndex - object->startIndex; double* vertexes = g->vertexes; double* colors = g->colors; glBegin(GL_TRIANGLES); { for(int i = 0; i < j; i++){ int coord = object->startIndex+i; int colorind = coord*4; double r,g,b,a; r = colors[colorind]; g = colors[colorind+1]; b = colors[colorind+2]; a = colors[colorind+3]; glColor4d( r,g,b,a); glVertex3d( vertexes[coord*3], vertexes[coord*3+1], vertexes[coord*3+2]); } } glEnd();
Yet regardless of what I put my triangle is always yellow, or the value of the first color in the colors array. I have gone into the debugger and checked the values on each individual loop iteration and the values of the r g b and a variables do infact change accordingly and are not always yellow, yet the result is a yellow triangle.
Yet if I put the following nabbed from the neheGL tutorials:
glClearColor(0.1f,0.1f,0.1f,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix //glTranslatef(1.5f,0.0f,0.0f); // Move Left 1.5 Units And Into The Screen 6.0 glBegin(GL_TRIANGLES); // Drawing Using Triangles glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red glVertex3f( 0.0f, 1.0f, 0.0f); // Top glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glEnd(); // Finished Drawing The Triangle glTranslatef(160.0f,0.0f,0.0f); // Move Right 3 Units glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only glBegin(GL_QUADS); // Draw A Quad glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glEnd();
I get a nice blended triangle with 3 colours from each vertex
Actually, I think I got it: you’re only seeing a small portion of the bottom left corner of your triangle. You need to move away from it to view it entirely: your coordinates are too large.