Log in or register to post comments

How can I draw more than one object with OpenGL 2.0?

October 28, 2011 - 9:23am #1

How can I draw a second object with OpenGL 2.0?

I have one object:

Quote:

QCAR::Matrix44F modelViewProjection;

SampleUtils::translatePoseMatrix(0.0f, 0.0f, 10.0f, // x, y, z
&modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale,
&modelViewMatrix.data[0]);
SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
&modelViewMatrix.data[0] ,
&modelViewProjection.data[0]);

glUseProgram(shaderProgramID);

glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*) &bikeVerts[0]);

glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &bikeNormals[0]);

glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &bikeTexCoords[0]);

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

glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjection.data[0] );

glDrawArrays(GL_TRIANGLES, 0, bikeNumVerts);

How can I draw a second object right next to it?
glPushMatrix and glPopMatrix no longer exists. :(

I'd be very happy if you could help me...

How can I draw more than one object with OpenGL 2.0?

July 2, 2012 - 3:32am #4

Hi dereklan

 

In the Image Targets sample if you add the following code (assuming you are using OpenGLES 2) it will render the 2nd teapot.

Note that the first line effectively resets the matrix and is necessary after drawing the first teapot.

 

HTH

N

            // second teapot

            modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());

            

            obj3D = [objects3D objectAtIndex:2];

            ShaderUtils::translatePoseMatrix(10.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);

            ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);

            ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);

            

            glUseProgram(shaderProgramID);

            

            glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);

            glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);

            glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);

            

            glEnableVertexAttribArray(vertexHandle);

            glEnableVertexAttribArray(normalHandle);

            glEnableVertexAttribArray(textureCoordHandle);

            

            glActiveTexture(GL_TEXTURE0);

            glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);

            glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);

            glDrawElements(GL_TRIANGLES, obj3D.numIndices, GL_UNSIGNED_SHORT, (const GLvoid*)obj3D.indices);

 

 

How can I draw more than one object with OpenGL 2.0?

July 2, 2012 - 2:09am #3

Is there a sample?

Re: How can I draw more than one object with OpenGL 2.0?

October 29, 2011 - 12:08pm #2

glPushMatrix and glPopMatrix are OpenGL ES 1.x concepts. You can use OpenGL ES 1.1 with QCAR, see the ImageTargets sample code and set the USE_OPENGL_ES_1_1 flag in Android.mk to true.

That said, you can of course do what you want with OpenGL ES 2.0 :) Simply use a fresh copy of the pose matrix returned by trackable->getPose(), and apply your transforms to it for your second object. Then repeat the rest of the steps.

- Kim

Log in or register to post comments