Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: lighting and viewports

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26

    lighting and viewports

    I'm having a few problems lighting my scene. I've setup my lighting properties and enabled lighting however the appearance of it is strange. It only shows any light when I'm looking in one direction,and when I move the camera it changes.

    Second thing, is I want to add a second viewport, but inside my current one? Basically I've rendered a TV, and I want it to display what I am currently looking at. Can this be done?

  2. #2
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    556

    Re: lighting and viewports

    From memory the OpenGL light positions in the fixed function Pipeline are affected by Matrix transformations. Try moving the location in your code that you set it's position.

    Putting a second viewport inside another viewport is very easy.
    From your description it may be as simple as redefining glViewport after you have drawn the tv surround and *not* clearing the screen.

    But if you are modelling this in 3D and want freedom of movement for the viewpoint then using an FBO and rendering the tv's image to a texture in that FBO which you can then texture onto the 'screen' of the tv in the main view is the best approach.

    http://www.songho.ca/opengl/gl_fbo.html

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26

    Re: lighting and viewports

    Hey. I've tried to create a FBO (I'm using JOGL rather than plain openGL) and I'm now getting an invalid memory access error

    Code :
    gl.glGenFramebuffersEXT(1, fbo, 0);
            gl.glGenRenderbuffersEXT(1, depthBuffer, 0);

    It seems that the error is in these 2 lines as this is all I haven't commented out and I still get the error.

    Code :
    gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, depthBuffer[0]);
            gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT, 14, 14);
            gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, depthBuffer[0]);
            gl.glGenTextures(1, customTex, 0);
            gl.glBindTexture(GL.GL_TEXTURE_2D, customTex[0]);
            gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8,  14, 14, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
            gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, customTex[0], 0);

    This is the rest yet it is still failing

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26

    Re: lighting and viewports

    ok bit further. No more errors however the texture it is rendering is blank. There is none. Simply white. Can you see why?

    Code :
    gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, depthBuffer[0]);
            gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT, GL.GL_DEPTH_COMPONENT, 14, 14);
            gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_DEPTH_ATTACHMENT_EXT, GL.GL_RENDERBUFFER_EXT, depthBuffer[0]);
            gl.glGenTextures(1, customTex, 0);
            gl.glBindTexture(GL.GL_TEXTURE_2D, customTex[0]);
            gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8,  14, 14, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
            gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, customTex[0], 0);
     
            gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fbo[0]);
            gl.glPushAttrib(GL.GL_VIEWPORT_BIT);
            gl.glViewport(0,0,14, 14);
     
            gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
            gl.glBegin(GL.GL_LINES);
                gl.glVertex3f(0.0f, 0.0f, 0.0f);
                gl.glVertex3f(10.0f, 10.0f, 10.0f);
            gl.glEnd();
     
            gl.glPopAttrib();
            gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
     
            gl.glBindTexture(GL.GL_TEXTURE_2D, customTex[0]);
            gl.glGenTextures(1, customTex, 0);
            gl.glBindTexture(GL.GL_TEXTURE_2D, customTex[0]);
            gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8,  14, 14, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, null);
            gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
            gl.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
            gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);
            gl.glGenerateMipmapEXT(GL.GL_TEXTURE_2D);
     
     
            gl.glDeleteFramebuffersEXT(1, fbo, 0);
            gl.glDeleteRenderbuffersEXT(1, depthBuffer, 0);

  5. #5
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: lighting and viewports

    You may miss mipmaps, try with min filter GL_LINEAR.
    Or generate mipmaps with glGenerateMipmapEXT.

    EDIT : sorry I did not read the whole source. Try anyway with min filter GL_LINEAR, maybe the mipmaps are not generated correctly.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26

    Re: lighting and viewports

    nope still not working. Changed to Linear and nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •