Log in or register to post comments

Custom Renderer

April 3, 2012 - 11:40am #1

Hi,
I try to draw something with my own vertex and fragment shader.
The result is really annoying.

For example, if I put these values in my vertex-array

				float crossVertex[] = {
				//Dreieck1
				0.0, 0.0, 0.0, 	 	
				-25.0, 50.0, 0.0,
				25.0, 50.0, 0.0, 
				
				//Dreieck2	
				0.0, 0.0, 0.0,				
				50.0, 25.0, 0.0,	 
				50.0, -25.0, 0.0, 
				
				//Dreieck3
				0.0, 0.0, 0.0,
				25.0, -50.0, 0.0, 	
				-25.0, -50.0, 0.0, 
				
				//Dreieck4
				0.0, 0.0, 0.0,
				-50.0, -25.0, 0.0, 	
				-50.0, 25.0, 0.0, 	

		glVertexAttribPointer(maPositionHandle, 3, GL_FLOAT, GL_FALSE, 0,
                              (const GLvoid*) &crossVertex[0]);

nothing happens

When I use another "size"-value inside of glVertexAttribPointer

Quote:

glVertexAttribPointer(maPositionHandle, 2, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &crossVertex[0]);

something really strange is plotted on the z-and y-axis.

When I write my vertices in a different order (change the last with the first value) my object is correctly drawn along the z an y axis. My reference for the axis is this image *[url]https://ar.qualcomm.at/resources/images/coordinateSystems.jpg*[/url].
I have realy no problem to rotate my object, but i don't understand why this happen?

Quote:

QCAR::Matrix44F modelViewProjection;
modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
//Farbiges Kreuz
SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
&modelViewMatrix.data[0] ,
&modelViewProjection.data[0]);

glUseProgram(customProgramID);
glVertexAttribPointer(maPositionHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &crossVertex[0]);
glVertexAttribPointer(maColorHandle, 3, GL_FLOAT, GL_FALSE, 0,
(const GLvoid*) &crossColor[0]);

glEnableVertexAttribArray(maPositionHandle);
glEnableVertexAttribArray(maColorHandle);

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

glDrawElements(GL_TRIANGLES, crossNumVerts, GL_UNSIGNED_SHORT,
(const GLvoid*) &crossIndices[0]);

greetz Robert

P.S.: Maybe someone has some good sides for OpenGL ES 2.0

Re: Custom Renderer

April 5, 2012 - 3:31am #6

Hi Kim,

I turned culling off and it works without rotation or any other tricks.
I think I have to take a deeper look into this OpenGL Method, because the right and left sides are different to the result which i get with the Metaio Mobile SDK. I think I have to switch it to clock wise.

Thank you for the tip!

Robert

Re: Custom Renderer

April 4, 2012 - 3:12pm #5

The code above looks okay, what did you have to change to get it to render? This is the correct coordinate system: https://ar.qualcomm.at/resources/images/coordinateSystems.jpg

Actually, did you have to turn off culling for this to work? I think by default counterclockwise polygons are front facing.

- Kim

Re: Custom Renderer

April 3, 2012 - 3:06pm #4

Thank you Kim,
so everything is alright when i use the same aspect ratio for my real image and the virtual image for the tracking.xml :)

Any idea about the coordinate System? Maybe I miss something in my logic or something else is wrong.

Re: Custom Renderer

April 3, 2012 - 2:19pm #3

The units are arbitrary. You establish the size of your target in the config.xml file (also when creating the target online, with the width field). You can certainly measure the printed target and use this for the size.

- Kim

Re: Custom Renderer

April 3, 2012 - 1:01pm #2

Ok I have now a result. I'm still confused about the coordinate system and the order of the values in a vertex. Whatever, this is my result:

Why I'm doing this? I want to find out a ratio for px in mm.
The result 1mm = 1px. Now I can place objects correctly on my image. Does this fits only on my smartphone or is it a common value?

Is there any formula to get the ratio between real and virtual object, or is it enough to know that there is a 1:1 situation?

Log in or register to post comments