can now visualize normals of GLUT geometry in GL2 mode as well

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1406 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2012-11-19 01:54:28 +00:00
parent 6b77283fc1
commit bc89db3fb9
2 changed files with 62 additions and 11 deletions

View File

@ -612,6 +612,8 @@ static void display(void)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSetOption(GLUT_OBJECTS_VISUALIZE_NORMALS,visNormals); /* Normals visualized or not? */
if (useShader && !shaderReady) if (useShader && !shaderReady)
initShader(); initShader();
@ -662,7 +664,6 @@ static void display(void)
else else
{ {
/* fixed function pipeline */ /* fixed function pipeline */
glutSetOption(GLUT_OBJECTS_VISUALIZE_NORMALS,visNormals); /* Normals visualized or not? */
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
if (persProject) if (persProject)
@ -713,8 +714,7 @@ static void display(void)
shapesPrintf (9, 1, "2D rotation (r)"); shapesPrintf (9, 1, "2D rotation (r)");
else else
shapesPrintf (9, 1, "1D rotation (r)"); shapesPrintf (9, 1, "1D rotation (r)");
if (!useShader) shapesPrintf (10, 1, "visualizing normals: %i (n)",visNormals);
shapesPrintf (10, 1, "visualizing normals: %i (n)",visNormals);
} else { } else {
/* print to command line instead */ /* print to command line instead */
printf ( "Shape %d slides %d stacks %d\n", function_index, slices, stacks ) ; printf ( "Shape %d slides %d stacks %d\n", function_index, slices, stacks ) ;

View File

@ -51,7 +51,10 @@ static void fghDrawGeometrySolid20(GLfloat *vertices, GLfloat *normals, GLsizei
/* declare function for generating visualization of normals */ /* declare function for generating visualization of normals */
static void fghGenerateNormalVisualization(GLfloat *vertices, GLfloat *normals, GLsizei numVertices, static void fghGenerateNormalVisualization(GLfloat *vertices, GLfloat *normals, GLsizei numVertices,
GLushort *vertIdxs, GLsizei numParts, GLsizei numVertIdxsPerPart); GLushort *vertIdxs, GLsizei numParts, GLsizei numVertIdxsPerPart);
static void fghDrawNormalVisualization(); #ifndef GL_ES_VERSION_2_0
static void fghDrawNormalVisualization11();
#endif
static void fghDrawNormalVisualization20(GLint attribute_v_coord);
/* Drawing geometry: /* Drawing geometry:
* Explanation of the functions has to be separate for the polyhedra and * Explanation of the functions has to be separate for the polyhedra and
@ -173,11 +176,22 @@ static void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLsizei nu
GLint attribute_v_coord = fgStructure.CurrentWindow->Window.attribute_v_coord; GLint attribute_v_coord = fgStructure.CurrentWindow->Window.attribute_v_coord;
GLint attribute_v_normal = fgStructure.CurrentWindow->Window.attribute_v_normal; GLint attribute_v_normal = fgStructure.CurrentWindow->Window.attribute_v_normal;
if (fgStructure.CurrentWindow->State.VisualizeNormals)
/* generate normals for each vertex to be drawn as well */
fghGenerateNormalVisualization(vertices, normals, numVertices,
vertIdxs, numParts, numVertIdxsPerPart);
if (fgState.HasOpenGL20 && (attribute_v_coord != -1 || attribute_v_normal != -1)) if (fgState.HasOpenGL20 && (attribute_v_coord != -1 || attribute_v_normal != -1))
{
/* User requested a 2.0 draw */ /* User requested a 2.0 draw */
fghDrawGeometrySolid20(vertices, normals, numVertices, fghDrawGeometrySolid20(vertices, normals, numVertices,
vertIdxs, numParts, numVertIdxsPerPart, vertIdxs, numParts, numVertIdxsPerPart,
attribute_v_coord, attribute_v_normal); attribute_v_coord, attribute_v_normal);
if (fgStructure.CurrentWindow->State.VisualizeNormals)
/* draw normals for each vertex as well */
fghDrawNormalVisualization20(attribute_v_coord);
}
#ifndef GL_ES_VERSION_2_0 #ifndef GL_ES_VERSION_2_0
else else
{ {
@ -185,13 +199,8 @@ static void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLsizei nu
vertIdxs, numParts, numVertIdxsPerPart); vertIdxs, numParts, numVertIdxsPerPart);
if (fgStructure.CurrentWindow->State.VisualizeNormals) if (fgStructure.CurrentWindow->State.VisualizeNormals)
{
/* generate normals for each vertex to be drawn as well */
fghGenerateNormalVisualization(vertices, normals, numVertices,
vertIdxs, numParts, numVertIdxsPerPart);
/* draw normals for each vertex as well */ /* draw normals for each vertex as well */
fghDrawNormalVisualization(); fghDrawNormalVisualization11();
}
} }
#endif #endif
} }
@ -506,7 +515,9 @@ static void fghGenerateNormalVisualization(GLfloat *vertices, GLfloat *normals,
} }
} }
static void fghDrawNormalVisualization() /* Version for OpenGL (ES) 1.1 */
#ifndef GL_ES_VERSION_2_0
static void fghDrawNormalVisualization11()
{ {
GLfloat currentColor[4]; GLfloat currentColor[4];
/* Setup draw color: (1,1,1)-shape's color */ /* Setup draw color: (1,1,1)-shape's color */
@ -524,6 +535,46 @@ static void fghDrawNormalVisualization()
free(verticesForNormalVisualization); free(verticesForNormalVisualization);
glColor4fv(currentColor); glColor4fv(currentColor);
} }
#endif
/* Version for OpenGL (ES) >= 2.0 */
static void fghDrawNormalVisualization20(GLint attribute_v_coord)
{
GLuint vbo_coords = 0;
if (attribute_v_coord != -1) {
fghGenBuffers(1, &vbo_coords);
fghBindBuffer(FGH_ARRAY_BUFFER, vbo_coords);
fghBufferData(FGH_ARRAY_BUFFER, numNormalVertices * 3 * sizeof(verticesForNormalVisualization[0]),
verticesForNormalVisualization, FGH_STATIC_DRAW);
}
if (vbo_coords) {
fghEnableVertexAttribArray(attribute_v_coord);
fghBindBuffer(FGH_ARRAY_BUFFER, vbo_coords);
fghVertexAttribPointer(
attribute_v_coord, /* attribute */
3, /* number of elements per vertex, here (x,y,z) */
GL_FLOAT, /* the type of each element */
GL_FALSE, /* take our values as-is */
0, /* no extra data between each position */
0 /* offset of first element */
);
fghBindBuffer(FGH_ARRAY_BUFFER, 0);
}
glDrawArrays(GL_LINES, 0, numNormalVertices);
if (vbo_coords != 0)
fghDisableVertexAttribArray(attribute_v_coord);
if (vbo_coords != 0)
fghDeleteBuffers(1, &vbo_coords);
/* Done, free memory */
free(verticesForNormalVisualization);
}
/** /**
* Generate all combinations of vertices and normals needed to draw object. * Generate all combinations of vertices and normals needed to draw object.