0

I'm modifying a matlab code. It displays graphics using the Psychtoolbox, which can basically create an on-screen window. The code I want to adapt uses both higher-level Psychtoolbox commands and lower-level OpenGL calls, as provided by the Matlab OpenGL toolbox. I'm familiar with Psychtoolbox, not at all familiar with OpenGL.

Coordinates in Psychtoolbox are in pixels and start on (0,0) from the top-left corner of the screen and move rightwards (x) and downwards (y).

I simply need the conversion between the Matlab implementation of OpenGL coordinates and Psychtoolbox's pixel-based ones. There are a few questions and answers and many resources online about this, but I am still confused.

For example, as far as I understand OpenGL uses normalized coordinates that range between [-1, 1]. However, in the code I am adapting something is nicely displayed despite y = -1.5.

So my questions are:

  1. How do I convert between Matlab's OpenGL and Matlab's Psychtoobox coordinates?
  2. Can OpenGL coordinates in Matlab go beyond the [-1, 1] range?
elisa
  • 965
  • 9
  • 27
  • OpenGL uses a viewport (i.e. window pixels) where coordinates start at botton-left an increase right and up. But the coordinates you must use are not from pixels but from vertices. What data do you have? – Ripi2 Mar 24 '17 at 17:38
  • I don't really understand the question, clearly because I'm not understanding something fundamental. OpenGL's coordinate system seems centered on the midpoint of the Psychtoolbox one. Then, different elements of the display are defined with coordinates that seem to be relative to that midpoint. Not sure this answers your question tough. – elisa Mar 24 '17 at 17:55
  • 1
    Typical OpenGL procedure: you have objects defined by triangles (or lines or just points) with vertices with some coordinates. Objects have their own "local" coordinates system (CS). With some matrix math you change every vertex coordinates to a unique, common to all, CS, the "World space". Then more matrix to change CS to the one "seen" by a camera. ("View space"). Then project into a plane, but transform also "z" coordinate, so still is 3D data. This last "box" CS is called "Normalized Device Coordinates system" (NDC). This have axis at center, X to right, Y to up, Z deep to screen. – Ripi2 Mar 24 '17 at 18:06
  • Thanks. This is already helpful. At least it explains that the information I was after does not exist. Will try to figure this out. – elisa Mar 24 '17 at 18:08
  • You have data... in what CS? – Ripi2 Mar 24 '17 at 18:10
  • I'm honestly not sure but it seems to be NDC. – elisa Mar 24 '17 at 18:18
  • Another hint: OpenGL automatically "expands" NDC to window sizes defined with `glViewport()` – Ripi2 Mar 24 '17 at 18:27
  • Thanks for all your help. I have no -explicit, at least- call to glViewport in the code -or in any of the functions it calls. – elisa Mar 24 '17 at 18:33

0 Answers0