Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    1,233

    Weird OPENGL Behaviour (C++)

    I'm currently messing around with some openGL using C++ and have set up a few functions to create a cube (and scale by the value held by a parameter to the DrawCube() function) and also have a function nLoadTexture2D(...) to load a texture into the frame buffer using SOIL.

    But I run into a problem when the scene is rendered. When viewed from the left (looking -x) the cubes and textures "interact" well with each other, meaning you get proper depth clipping (?) of objects obscuring other objects.

    However when viewed along the +x axis, you get the result in the screenshot below:



    I'm sure it's a pretty trivial solution for someone versed in openGL, but I'm stumped and my eyes hurt from sifting through Google pages (since I'm not quite sure what to call this).

    Thanks a head of time.
    Intel Core i3 2120 running @ 3.30 Ghz && 8GB Corsair Vengeance RAM @ 1333Mhz && XFX Radeon HD 6850 @ 1920x1080 && 600w PSU && 2TB In-Case Storage (Boot drive: OCZ Vertex 4 128GB SSD) && ASUS P8H77-V LE Mobo && ThermalTake Tsunami Dream Case && Black Widow Mechanical Keyboad && Thermaltake Black Gaming Mouse

  2. #2
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,349
    Did you enable depth testing?

    Code:
    glEnable(GL_DEPTH_TEST);
    Also, ensure that your vertex shader does what it's supposed to do and check whether you messed with the depth function somewhere.

  3. #3
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    1,233
    Got it. Thanks a bunch. Stupid mistake on my part, had a hidden glDisable (GL_DEPTH_TEST) in a function I must have looked over.
    Intel Core i3 2120 running @ 3.30 Ghz && 8GB Corsair Vengeance RAM @ 1333Mhz && XFX Radeon HD 6850 @ 1920x1080 && 600w PSU && 2TB In-Case Storage (Boot drive: OCZ Vertex 4 128GB SSD) && ASUS P8H77-V LE Mobo && ThermalTake Tsunami Dream Case && Black Widow Mechanical Keyboad && Thermaltake Black Gaming Mouse

  4. #4
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    1,233
    Problem is, now I have a super-massive black hole of a memory leak. I used a memory validator to check for where it's leaking and pretty much every single entry has to do with ati driver dlls. I tried to seach for the dlls and "memory leak" in google, but most of the results are for run-time crashes for games and such, no nitty gritty stuff.

    -_- Any help (or even a little insight) is greatly appreciated.
    Intel Core i3 2120 running @ 3.30 Ghz && 8GB Corsair Vengeance RAM @ 1333Mhz && XFX Radeon HD 6850 @ 1920x1080 && 600w PSU && 2TB In-Case Storage (Boot drive: OCZ Vertex 4 128GB SSD) && ASUS P8H77-V LE Mobo && ThermalTake Tsunami Dream Case && Black Widow Mechanical Keyboad && Thermaltake Black Gaming Mouse

  5. #5
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    1,233
    Here is the entire code for anyone with enough time to skim for any user-errors.

    Sorry if pastebin ruined my formatting. Also, please keep criticisms to the issue at hand, or other MAJOR things in need of revision. Not personal opinions or things beyond the scope of what is necessary.

    Thanks!

    http://pastebin.com/fdYFS7R0
    Intel Core i3 2120 running @ 3.30 Ghz && 8GB Corsair Vengeance RAM @ 1333Mhz && XFX Radeon HD 6850 @ 1920x1080 && 600w PSU && 2TB In-Case Storage (Boot drive: OCZ Vertex 4 128GB SSD) && ASUS P8H77-V LE Mobo && ThermalTake Tsunami Dream Case && Black Widow Mechanical Keyboad && Thermaltake Black Gaming Mouse

  6. #6
    Join Date
    Oct 2006
    Location
    Melbourne
    Posts
    743
    Just had a quick check so far, reading it online at pastebin. From the cursory look I gave it, it seems that you've got texture-loading going on left-right and center. (if you'll pardon the spatial pun)

    Can't see a single free or delete in the code, yet it seems that E A C H . A N D . E V E R Y time you draw geometry with a texture on it that you are loading that texture. :eeek:

    With that in mind, it seems that "super-massive black hole of a memory leak" was if anything an understatement. :chuckles:

    If I were you (I won't bother tonight, would have to find/create some textures and a routine to load them on my hdd)
    I would:
    • create a new function that would load all of your textures
    • Load each of these into an array of GLuint's - perhaps something like GLuint textures[2]; (since you've got ground and mushroom img maps)
    • Just once per time the app is run, load these two textures and put them into the above array - make it global so all functions can see it. For the purposes of this example, assume I've loaded the ground into textures[0] and the mushroom into textures[1]
    • Then when it comes time to drawing your geometry, simply glBindTexture[0] when you're about to draw geom that needs the ground, while glBindTexture[1] when you're about to draw geom that needs the mushroom texture.


    EDIT: Just chopped up all of your code and pasted it into a bunch of files, to see just how much work I'd need to give it to get something working. I just commented out the actual calls to SOIL_LoadTexture, or whatever it's called, replacing them with calls increment a counter.
    Woooauw!
    I just threw a call to printf to display the value in the reshape function (dont want to bog down the system with a bazillion printf calls in the main loop, so I just put them somewhere I could control them. Easy, size the window, get a status update.)
    Here you go, check this out:
    Num texLoads: 31100
    Num texLoads: 31104

    Process returned 0 (0x0) execution time : 25.614 s
    Since you're only using two different images, the Num texLoads should be precisely 2 - for the entire life of the program.. (it's 4 each time the screen is repainted when dragging continuously, right now)
    Last edited by enhzflep; 05-05-2012 at 07:28 AM. Reason: self evident

  7. #7
    Join Date
    Jan 2004
    Location
    Canada
    Posts
    1,233
    Great response, enhzflep. I didn't quite understand the way loading textures and binding them worked, you've clarified it perfectly for me. I had added glDeleteTexture after this post but was still going about binding and loading textures horribly wrong. I had fixed the memory leak with small numbers of geometry, but when the number grew, it appeared again.

    That is effectively GONE now, thanks to you. Also, thanks for drilling the point of how out of hand the code was without being condescending.

    +1!
    Intel Core i3 2120 running @ 3.30 Ghz && 8GB Corsair Vengeance RAM @ 1333Mhz && XFX Radeon HD 6850 @ 1920x1080 && 600w PSU && 2TB In-Case Storage (Boot drive: OCZ Vertex 4 128GB SSD) && ASUS P8H77-V LE Mobo && ThermalTake Tsunami Dream Case && Black Widow Mechanical Keyboad && Thermaltake Black Gaming Mouse

Posting Permissions

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