Results 1 to 5 of 5

Thread: glCopyTexImage2D

  1. #1

    glCopyTexImage2D

    Hi all,

    im trying to add a CCTV element, basicly i am rendering a certain section of my world to a texture and then rendering it on to a face in the world, except that it isnt working that way

    The CCTV class has a position and a direction that im setting the viewport to, and then render my world (without the CCTV textures) then using glCopyTexImage2D i assign it on to an already created (blank) texture, then i render my world (with the CCTV textures) but when i try and render my world to get the CCTV textures the whole screen goes blank, but if i dont then it goes ok except for the not having a texture problem.

    The code i use to get the CCTV textures is ::
    Code:
      glViewport(0,0,fWidth,fHeight);
    
      glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
      glLoadIdentity;
    
        glDisable(GL_DEPTH_TEST);
    
        fCamera.X := fPosition[0];
        fCamera.Y := fPosition[1];
        fCamera.Z := fPosition[2];
        fCamera.dX := fDirection[0];
        fCamera.dY := fDirection[1];
        fCamera.dZ := fDirection[2];
        fCamera.SetView;
    
      // Render my world
    
        fTexture.BindTexture;
        glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, fWidth, fHeight, 0);
    
      glEnable(GL_DEPTH_TEST);
      glViewport(0,0,vWidth,vHeight);
    This is being called just before the world is rendered so that it is updated, then as im rendering the world i check to if the face has a CCTV texture, if so it is rendered.

    thanx for any help
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    glCopyTexImage2D

    I think your approach is correct and I don't see any problem with the code you posted. (given that the custom methods you call work as they are supposed to ) What are the values of fwidth and fheight? They should be the size of the texture and power of two, but I guess you know this allready!

    If you flip the buffer after rendering the scene the first time (for the cctv-texture) you should see the complete scene on your screen but in the size of the texture in the low left corner. does it work?

    and my last question: how do you generate the blank texture?

    greetings,
    -lith
    programming is more than copy and paste!

  3. #3

    glCopyTexImage2D

    hi,

    The values for Height and Width are 256.

    Yes if i dont resize the viewport then i get the world rendered in the lower left cornour. Is their away to get it to render from a different position in the world than i am, cause i have tried to move the camera then create the texture and move it back but this some reason screws everything up :?

    I have a texture class that when is created it either loads a texture and records the Index, or it creates a Blank texture and records its Index, I create the blank texture by ::
    Code:
      procedure glGenTextures&#40;n&#58; GLsizei; var textures&#58; GLuint&#41;; stdcall; external opengl32;
    
      procedure BlankTexture;
      var
        pData&#58; Pointer;
      begin
        GetMem&#40;pData, 256*256*3&#41;;
    
        glGenTextures&#40;1, fIndex&#41;;
        glBindTexture&#40;GL_TEXTURE_2D, fIndex&#41;;
        glTexEnvi&#40;GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE&#41;;  &#123;Texture blends with object background&#125;
    
        glTexImage2D&#40;GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pData&#41;;  // Use when not wanting mipmaps to be built by openGL
        glTexParameteri&#40;GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR&#41;; &#123; only first two can be used &#125;
        glTexParameteri&#40;GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR&#41;; &#123; all of the above can be used &#125;
    
        FreeMem&#40;pData&#41;;
      end;
    Would using ARB_Multitexture effect this in anyway?
    When i use glBindTexture i get a blank screen, but if i bind it to a layer i dont get the texture but the world is still rendered?!?
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    glCopyTexImage2D

    The parts of code you posted should just work fine...

    Quote Originally Posted by M109uk
    Yes if i dont resize the viewport then i get the world rendered in the lower left cornour
    Well, then there shouldn't be any problems to copy the framebuffer into the texture after rendering. :-/

    Quote Originally Posted by M109uk
    Would using ARB_Multitexture effect this in anyway?
    No, that shouldn't be necessary...

    Quote Originally Posted by M109uk
    When i use glBindTexture I get a blank screen, but if i bind it to a layer i dont get the texture but the world is still rendered?!?
    ?!? When you use wich glBindTexture where? You don't try to bind the blank texture _before_ rendering the world, do you? and what is a layer in your case?

    Quote Originally Posted by M109uk
    Is their away to get it to render from a different position in the world than i am, cause i have tried to move the camera then create the texture and move it back but this some reason screws everything up :?
    If your camera class works as it is supposed to, it should allow you to view the world from every position you wish. However, you might want to try saving the matrix by pushing it onto the stack before moving the camera. That way you can restore the former position without moving the camera back...

    Hmm. Sorry, that I can't help you but I'm pretty sure that the parts of code you posted are okay... If you want I could have a look at the whole project or respective an excerpt illustrating the problem.

    -lith
    programming is more than copy and paste!

  5. #5

    glCopyTexImage2D

    Hi,

    I have finally managed to get it working, i think the problem was that i didnt have the glPushMatrix and glPopMatrix in the right places :roll:
    and the same reason for the camera class lol

    i am using Layer0 and Layer1 with GL_ARB_Multitexture, but it doesnt seem to make any difference if i bind it to either of the layers or just use glBindTexture.

    if your intrested this is how it looks now ::
    [pascal]
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

    Textures.InactiveLayer0; // Deactivate ARB Layer 0
    Textures.InactiveLayer1; // Deactivate ARB Layer 1

    glDisable(GL_DEPTH_TEST);

    glViewport(0,0,256,256);
    glPushMatrix;
    glLoadIdentity;

    glRotatef(-fDirection[0], 1, 0, 0);
    glRotatef(-fDirection[1], 0, 1, 0);
    glRotatef(-fDirection[2], 0, 0, 1);
    glTranslatef(-fPosition[0], -fPosition[1], -fPosition[2]);

    // Render world!

    fTexture.BindTexture; { glBindTexture(GL_TEXTURE_2D, fTexture.Index); }
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 256, 256, 0);
    glPopMatrix;
    glBindTexture(GL_TEXTURE_2D, 0);

    glEnable(GL_DEPTH_TEST);

    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

    glViewport(0,0,vWidth,vHeight);
    [/pascal]

    Thanx for your help
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Bookmarks

Posting Permissions

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