Log in or register to post comments

rendering models

November 25, 2013 - 4:33am #1

Supose i have correctly initialized these elements in order to render some models:

// Textures:

int textureCount = 0;
Texture** textures = 0;

// Models 
int modelCount = 0;
Model **models = 0;
 
Now, i want to render these models and textures. I have created a function in order to render a model.
This simplified function is, more or less, like this:
 
void renderModel(const QCAR::TrackableResult* trackableResult, const Model* m, const Texture *t) {

// Choose the texture
const Texture* const thisTexture = t;

QCAR::Vec2F targetSize = imageTarget.getSize();

const QCAR::ImageTarget& imageTarget =
(const QCAR::ImageTarget&) trackableResult->getTrackable();

QCAR::Matrix44F modelViewProjection;
QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(
trackableResult->getPose());

SampleUtils::translatePoseMatrix(translateX, translateY, 0.0f,&modelViewMatrix.data[0]);
SampleUtils::scalePoseMatrix(targetSize.data[0], targetSize.data[1],1.0, &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*) &m->vertices[0]);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0,(const GLvoid*) &m->normals[0]);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,(const GLvoid*) &m->textCoords[0]);

glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);

glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);

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

glDrawElements(GL_TRIANGLES, m->mIndicesLength, GL_UNSIGNED_SHORT,
(const GLvoid*) &m->indices[0]);

glDisableVertexAttribArray(vertexHandle);
glDisableVertexAttribArray(normalHandle);
glDisableVertexAttribArray(textureCoordHandle);
SampleUtils::checkGlError("ImageTargets renderFrame");
}

 

 
So the render frame method is like this:
 
JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(
JNIEnv * env, jobject obj) {

// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Get the state from QCAR and mark the beginning of a rendering section
QCAR::State state = QCAR::Renderer::getInstance().begin();

// Explicitly render the Video Background
QCAR::Renderer::getInstance().drawVideoBackground();

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

if (QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection
== QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
glFrontFace(GL_CW);  //Front camera
else
glFrontFace(GL_CCW);   //Back camera

// assuming this is an image target, did we find any trackables this frame?
for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {

// Get the trackable:
const QCAR::TrackableResult* result = state.getTrackableResult(tIdx);

//render all models
for(int i=0; i<modelCount; i++){
renderModel(result, models[i],textures[i]);
}
}

glDisable(GL_DEPTH_TEST);
QCAR::Renderer::getInstance().end();
}

 

 
Then, i try to test. And it looks ok. I can render for example, 8 teapots.
The extrange problem is when i try to render more than 8 models (for example 9 teapots). 
After rendering i get the following error:
 
Fatal signal 11 (SIGSEGV) at 0x002f007d (code=1), thread 2753 (Thread-169567)
 
Can anybody help me
Thanks in advance
 
 
 
 
 

rendering models

November 25, 2013 - 6:36am #2

I have solved it.

I would like to create a tutorial in order to show how to render more than one model.

I think it's a good solution, because you can:

- Specify the real size (in mm) of the models

- Specify the final output position (in mm) of the model related to the image target

- Render all the models you want

 

Where is the best place to locate this tutorial?

Thanks in advance

Log in or register to post comments