Sign in to follow this  
AlexBlack

Matrixes and coordinates

Recommended Posts

Hello all.

I have a quad with texture. Set viewport and matrixes:
[source lang="python"]glViewport(0, 0, self._size[0], self._size[1])
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0, self._size[0], self._size[1], 0, -1, 1)

glMatrixMode(GL_MODELVIEW)
glLoadIdentity()[/source]

Vertex and texture coordinates:
[source lang="python"]
coordarr = [[0, self._size[1], 0, 0, 0, 0],
[self._size[0], self._size[1], 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0],
[self._size[0], 0, 0, 1, 1, 0]]
[/source]

There is some scaling in shader, so quad doesn't change shapes when window is resizing.
[source lang="python"]gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex
* vec4(image_width/viewport_width, image_height/viewport_height, 1, 1)
[/source]

I try to draw some markup on the quad, for example crosses made from GL_LINES. Their positions compute from real image coordinates
[source lang="python"]markup_x = (real_x / self._image.shape[1]) * self._size[0]
markup_y = (real_y / self._image.shape[0]) * self._size[1]
[/source]
I set the same matrixes and coordinates to shader that draws markup, apply the same scaling. But crosses display incorrect, their shapes depend on viewport size, so they stretch and shrink.


But if I set glOrtho(-1, 1, 1, -1, -1, 1) everywhere and coordinates:
[source lang="python"] coordarr = [[-1, 1, 0, 0, 0, 0],
[ 1, 1, 0, 1, 0, 0],
[-1, -1, 0, 0, 1, 0],
[ 1, -1, 0, 1, 1, 0]][/source]
Also some changes in crosses coordinates computation
[source lang="python"] markup_x = (real_x / float(self._image.shape[1])) * 2 - 1
markup_y = (real_y / float(self._image.shape[0])) * 2 - 1[/source]

... and shaders code leave the same, markup displays correct. I guess that problem in matrixes, but cannot find it. What I'm doing wrong?

Thanks a lot.

Share this post


Link to post
Share on other sites
I need to display markup (crosses) correctly. Currently their shapes depend on viewport size, so they stretch and shrink. Edited by AlexBlack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this