rashwinr / opengles-book-samples

Automatically exported from code.google.com/p/opengles-book-samples
0 stars 0 forks source link

glDrawElements call with wrong type in Simple_TextureCubemap example #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Compile the code of Chapter_9/Simple_TextureCubemap.
2. Try to execute compiled binary with OpenGL ES 2.0 lilbrary

What is the expected output? What do you see instead?
Expected result: To see a sphere.
Real result: No sphere.

What version of the product are you using? On what operating system?
Source from trunk (2012-05-27).
Using Mali's OpenGL ES 2.0 emulator.

Please provide any additional information below.
glDrawElements is called with type GL_UNSIGNED_INT which according to OpenGL ES 
2.0 specification is not supported. That generates GL_INVALID_ENUM error.
For reference see the description of glDrawElements() at: 
http://www.khronos.org/opengles/sdk/docs/man/

To be fixed GL_UNSIGNED_SHORT should be used instead of GL_UNSIGNED_INT. 
esShapes.c and and esUtil.h files should be changed accordingly. You can find 
my fix bellow. I've just compiled this example and not the other. So there may 
be the same error in them also.

--------------------- Fix start -----------------------

diff -r -x.svn -u3 
svn_trunk/opengles-book-samples-read-only/LinuxX11/Chapter_9/Simple_TextureCubem
ap/Simple_TextureCubemap.c 
workCopy/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c
--- 
svn_trunk/opengles-book-samples-read-only/LinuxX11/Chapter_9/Simple_TextureCubem
ap/Simple_TextureCubemap.c  2012-05-27 13:25:58.376169537 +0300
+++ workCopy/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c    2012-05-27 
13:57:57.293899986 +0300
@@ -34,7 +34,7 @@
    int      numIndices;
    GLfloat *vertices;
    GLfloat *normals;
-   GLuint *indices;
+   GLushort *indices;

 } UserData;

@@ -184,7 +184,7 @@
    glUniform1i ( userData->samplerLoc, 0 );

    glDrawElements ( GL_TRIANGLES, userData->numIndices, 
-                    GL_UNSIGNED_INT, userData->indices );
+                    GL_UNSIGNED_SHORT, userData->indices );
 }

 ///
diff -r -x.svn -u3 
svn_trunk/opengles-book-samples-read-only/LinuxX11/Common/esShapes.c 
workCopy/Common/esShapes.c
--- 
svn_trunk/opengles-book-samples-read-only/LinuxX11/Common/esShapes.c    2012-05-27 
13:25:58.348169402 +0300
+++ workCopy/Common/esShapes.c  2012-05-26 23:43:42.619519502 +0300
@@ -52,7 +52,7 @@
 ///         if it is not NULL ) as a GL_TRIANGLE_STRIP
 //
 int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals, 
-                             GLfloat **texCoords, GLuint **indices )
+                             GLfloat **texCoords, GLushort **indices )
 {
    int i;
    int j;
@@ -72,7 +72,7 @@
       *texCoords = malloc ( sizeof(GLfloat) * 2 * numVertices );

    if ( indices != NULL )
-      *indices = malloc ( sizeof(GLuint) * numIndices );
+      *indices = malloc ( sizeof(GLushort) * numIndices );

    for ( i = 0; i < numParallels + 1; i++ )
    {
@@ -108,7 +108,7 @@
    // Generate the indices
    if ( indices != NULL )
    {
-      GLuint *indexBuf = (*indices);
+      GLushort *indexBuf = (*indices);
       for ( i = 0; i < numParallels ; i++ ) 
       {
          for ( j = 0; j < numSlices; j++ )
diff -r -x.svn -u3 
svn_trunk/opengles-book-samples-read-only/LinuxX11/Common/esUtil.h 
workCopy/Common/esUtil.h
--- 
svn_trunk/opengles-book-samples-read-only/LinuxX11/Common/esUtil.h  2012-05-27 
13:25:58.348169402 +0300
+++ workCopy/Common/esUtil.h    2012-05-26 23:44:36.819788237 +0300
@@ -21,6 +21,7 @@
 //  Includes
 //
 #include <GLES2/gl2.h>
+#include <GLES2/gl2ext.h>
 #include <EGL/egl.h>

 #ifdef __cplusplus
@@ -185,7 +186,7 @@
 ///         if it is not NULL ) as a GL_TRIANGLE_STRIP
 //
 int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals, 
-                             GLfloat **texCoords, GLuint **indices );
+                             GLfloat **texCoords, GLushort **indices );

 //
 /// \brief Generates geometry for a cube.  Allocates memory for the vertex data and stores 

---------------------- Fix end ------------------------

Original issue reported on code.google.com by somem...@abv.bg on 27 May 2012 at 11:20