Jump to content
  • Advertisement
Sign in to follow this  
VansFannel

OpenGL Find seven differences between these two images.

This topic is 2841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

Sorry for the joke.

I'm developing an Android application with OpenGL ES 2.0 as native code C++.

I'm testing my code with a teapot model. For the two images shown below I use the same data and same code.

In the first image I'm retrieving data from a header file.



For the second image I have copied all vertices and indices data inside two JAVA classes. Using JNI, I pass all data to C++ native code and pointers to vertices elements.



Code is the same on both cases, I only change static arrays for pointers.

Here is rendering code using static arrays:


JNIEXPORT void JNICALL Java_com_xxx_xxxxxx_ActivityRenderer_renderFrame
(JNIEnv *env, jobject obj)
{
// modelViewProjection initialization code HERE

glUseProgram(shaderProgramID);

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotVertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotNormals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &teapotTexCoords[0]);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
(const GLvoid*) &teapotIndices[0]);
}






teapotVertices, teapotNormals and teapotTexCoords are static const float teapot...[...]
teapotIndices is static const unsigned short teapotIndices[NUM_TEAPOT_OBJECT_INDEX]

And here when I use pointers (all vertices data is passed from Java to C++ using JNI).

JNIEXPORT void JNICALL Java_com_xxx_xxxxxx_ActivityRenderer_renderFrame
(JNIEnv *env, jobject obj,
jfloatArray vertices, jfloatArray normals,
jfloatArray texCoord, jintArray indices)
{
jfloat *vertPos, *vertNorm, *vertTexC;
jint *indicesArray;

// Get array length
jsize numNormals = env->GetArrayLength(normals);
jsize numTexCoords = env->GetArrayLength(texCoord);

// Get indices' number
GLsizei numIndices = (GLsizei) env->GetArrayLength(indices);

// Get a pointer to array's elements pass as arguments
vertPos = env->GetFloatArrayElements(vertices, 0);
indicesArray = env->GetIntArrayElements(indices, 0);

if (numNormals > 0)
vertNorm = env->GetFloatArrayElements(normals, 0);
if (numTexCoords > 0)
vertTexC = env->GetFloatArrayElements(texCoord, 0);

// modelViewProjection initialization code HERE

glUseProgram(shaderProgramID);

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) vertPos);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) vertNorm);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) vertTexC);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );
glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT,
(const GLvoid*) indicesArray);

glDisableVertexAttribArray(vertexHandle);
glDisableVertexAttribArray(normalHandle);
glDisableVertexAttribArray(textureCoordHandle);

// I'm not sure but my problems come from here:
env->ReleaseFloatArrayElements(vertices, vertPos, 0);
if (numNormals > 0)
env->ReleaseFloatArrayElements(normals, vertNorm, 0);
if (numTexCoords > 0)
env->ReleaseFloatArrayElements(texCoord, vertTexC, 0);
env->ReleaseIntArrayElements(indices, indicesArray, 0);
}







As you can see, I've only changed vertices coordinates, normals and texture coordinates from static to dynamic array.

I have also checked values and are the same when using static arrays and pointers.

May I need to use buffers? (glGenBuffers, glBindBuffer and glBufferData)

Any advice?

[Edited by - VansFannel on December 11, 2010 8:12:05 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!