0

I'm working on a project using JOGL API.

Now I am stuck at a point that is the followed:

-I run the program and it shows a Canvas divided in 4 viewPorts. The objective of the project is basically in each of the viewPorts we need to "project" an object from 4 diferent points of view. But first, we need to when clicking [1,2,3,4] to "expand"/"full-screen" the matched ViewPort.

My idea is when clicking any number create a new viewPort like this:gl.glViewport(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT). But this only creates a new viewPort with the size of the canvas.

How can I expand the "content" of any of the 4 viewPort to "enter" that new viewPort?

Tito
  • 298
  • 2
  • 5
  • 20

1 Answers1

2

I think you've got confused what glViewport does. I don't know what you think it does (not), but what it's specified to do is, to set the portion of the OpenGL window, to which to map the post-projection (NDC) space. Or in layman terms, you use it to determine where in the window things get drawn. If you want to render full screen: Make the window full screen and set the viewport to the window size.

If you want to "expand" an existing drawing, you have to set the proper viewport and redraw the parts in question.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • basically I have the canvas divided by 4 viewPorts and I want to, when clicking on [1,2,3,4], it chooses one of the 4 viewPorts and set THAT viewPort to the window size. You know how can it be made? Thanks in advance! – Tito Nov 26 '14 at 09:57
  • did you understood what I said? – Tito Nov 26 '14 at 10:32
  • 2
    @Afonso: Yes, I understood you. All you have to do is set `glViewport` to the window size and redraw the scene of that one "view" you'd like to expand. OpenGL is just drawing things; it does not handle events and it doesn't manage a scene. – datenwolf Nov 26 '14 at 11:03
  • "redraw the scene of that one "view" you'd like to expand". How can I do that? And if you say that it does not handle events, how can I select wich viewPort I would like to "expand" by typing in the keyboard [1,2,3,4]? Thanks! – Tito Nov 26 '14 at 13:14
  • 1
    @Afonso: You redraw by doing a redraw (yes, I know that's a tautology). Well you used *something* to create an OpenGL window (GLUT, GLFW, the low level OS APIs, Qt, etc.); you must use *that something* to receive input events. Process these events in an appropriate way (`if( clickcoordinates within viewport[n] ) then …`) , set variables determine which viewport to draw where and issue a redraw condition. Nothing of that is OpenGL though. – datenwolf Nov 26 '14 at 13:26
  • My idea is to my class extends KeyListener and in the method keyPressed(KeyEvent e) have a switch case to assign to a global variable the number of the key pressed. Next, in the display I have a switch case with 1 2 3 4. There I need to create a viewPort with the size of the window like this: gl.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT). What I need to do next? I'm not getting it when you say redraw because the teacher gave us plenty of code and we are a bit 'lost'. GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); – Tito Nov 26 '14 at 14:51
  • Then we have a method displayGround(gl) that builds the ground of the viewPort and displayScene(gl); that builds the current object. Any tips? – Tito Nov 26 '14 at 14:53
  • @Afonso: I'd start by figuring out, where those `display…` functions are called from and then figure out, how to trigger this code path. *BTW: Nothing is _built_ in OpenGL. Things are just drawn. OpenGL is nothing more than a sophisticated pencil to draw on a window's "paper".* – datenwolf Nov 26 '14 at 14:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65697/discussion-between-afonso-and-datenwolf). – Tito Nov 26 '14 at 15:13
  • Just look at your flag in GLEventListener.display(). – gouessej Nov 26 '14 at 21:15