Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Image vanishes on resize

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    7

    Image vanishes on resize

    I call ResizeScene initially in setting up. I call it when the user resizes the window. Everything is fine after the first call, but after a second call to ResizeScene, my nice rotating triangle is no longer visible. Could someone look at the relevant code below and maybe spot why that happens? I had this working right before, but I lost my source code and started over from scratch. This time around it doesn't work right.

    Thanks

    Public Sub Triangle()
    Gl.glBegin(Gl.GL_TRIANGLES)
    Gl.glColor3f(1, 0, 0) : Gl.glVertex3f(0, 1, 0)
    Gl.glColor3f(0, 1, 0) : Gl.glVertex3f(0.87, -0.5, 0)
    Gl.glColor3f(0, 0, 1) : Gl.glVertex3f(-0.87, -0.5, 0)
    Gl.glEnd()
    End Sub

    Private Sub DrawScene()
    Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)
    Gl.glLoadIdentity()
    Gl.glRotatef(ElapsedTime * 0.1, 0, 0, 1)
    s.Triangle()
    Gl.glFlush()
    Gdi.SwapBuffers(hDC)
    End Sub

    Public Sub ResizeScene(ByVal w As Integer, ByVal h As Integer)
    If h = 0 Then h = 1
    Gl.glViewport(0, 0, w, h)
    Gl.glMatrixMode(Gl.GL_PROJECTION)
    Gl.glLoadIdentity()
    Glu.gluPerspective(45.0, w / h, 1.0, 100.0)
    Gl.glMatrixMode(Gl.GL_MODELVIEW)
    Gl.glLoadIdentity()
    Application.DoEvents()
    End Sub

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Image vanishes on resize

    have you enabled the depth test?
    Just before window resizing do you see the triangle rotating?

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: Image vanishes on resize

    Maybe the value of the aspect ratio equals zero in

    Glu.gluPerspective(45.0, w / h, 1.0, 100.0)

    if w and h are treated as integers. Is it possible that you start with a square window (aspect=1) and then resize to w<h so that aspect=0?

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    7

    Re: Image vanishes on resize

    >Just before window resizing do you see the triangle rotating?
    Yes, until I grab the corner of the window and stretch it, the triangle rotates at a nice constant speed, about the z-axis, facing the viewer.

    >have you enabled the depth test?
    No, I hadn't. Now I have, and use GL_LEQUAL as my dpeth func. No change.

    Thanks

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    7

    Re: Image vanishes on resize

    >Maybe the value of the aspect ratio equals zero in
    In this app I force a square client area for the window and use the client area dimensions to set up my viewport and perspective.

    w / h always equals 1.

    Thanks

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Image vanishes on resize

    So why don't you put 1.0 for the aspect ration instead of w/h ??
    Just to be sure, I suppoze you have already done this, have you the same problem with 1.0 for aspect ratio?

    How do you create your window? using glut, win api, ...?

    It looks like that after resizing the window is not redrawn by opengl, are you sure that the ogl draw function is called? You can put a printf or cout in the draw function (hardcore but efficient)

  7. #7
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    7

    Re: Image vanishes on resize

    >So why don't you put 1.0 for the aspect ration instead of w/h ??
    In the general case, I make the viewport match the client area of the window. It so happens, in this app, I force a square window client area, so w=h, therefore the aspect ratio is always 1.

    >Just to be sure, I suppoze you have already done this, have you
    >the same problem with 1.0 for aspect ratio?
    Yes I did, and Yes, the problem remained.

    >How do you create your window? using glut, win api, ...?
    Ultimately win api, via .Net

    >It looks like that after resizing the window is not redrawn by
    >opengl, are you sure that the ogl draw function is called? You
    >can put a printf or cout in the draw function (hardcore but
    >efficient)
    I have tested this, and yes, the OpenGL drawing is still called.

    Thanks

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: Image vanishes on resize

    Maybe you can try removing the glFlush call. I remember that some implementations swap buffers on a glFlush call. This would mean you are swapping the buffer twice. I know it's far fetched, but it's strange that something this simple doesn't work...

  9. #9
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    7

    Re: Image vanishes on resize

    >Maybe you can try removing the glFlush call. I remember that
    Thank you. Well, I just tried it. No difference.

    >but it's strange that something this simple doesn't work...
    Agreed!

    Jon

  10. #10
    Senior Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    990

    Re: Image vanishes on resize

    Aha! Are you sure your ResizeScene function is getting called at startup? Going by the coordinates of your triangle vertices, I doubt that your triangle will be inside the view frustum of your gluPerspective call...

Page 1 of 2 12 LastLast

Similar Threads

  1. Image vanishes when I call glutpostredisplay()
    By lunixer in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-10-2011, 08:34 AM
  2. Image Texture Resize using glsl
    By oaraf in forum OpenGL: GLSL
    Replies: 2
    Last Post: 02-16-2011, 01:22 AM
  3. Need Help on how to resize texture image...
    By G-O-H in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-10-2008, 12:05 AM
  4. Resize Window\Resize Image
    By Cerv36 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-16-2003, 04:42 AM
  5. Losing Image On Resize
    By Tweener in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-22-2002, 05:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean