Results 1 to 9 of 9

Thread: glBuild2DMipmaps

  1. #1
    Junior Member Newbie
    Join Date
    May 2006
    Location
    Louisiana
    Posts
    12

    glBuild2DMipmaps

    I've been having a problem with my program crashing, I know this isn't 100% an opengl problem.. but maybe someone could offer some suggestions? It's crashing were marked..
    code here:
    http://rafb.net/paste/results/NOVfUe55.html

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: glBuild2DMipmaps

    You are passing a pointer to a vector to gluBuild2DMipmaps.

    A vector is not the same as a typical C-Array, no wonder it crashes.

    Look at some tutorials, to see how to do it right:
    nehe.gamedev.net

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Senior Member Frequent Contributor Mars_999's Avatar
    Join Date
    Mar 2001
    Location
    Sioux Falls, SD, USA
    Posts
    519

    Re: glBuild2DMipmaps

    Originally posted by Jameson Quave:
    I've been having a problem with my program crashing, I know this isn't 100% an opengl problem.. but maybe someone could offer some suggestions? It's crashing were marked..
    code here:
    http://rafb.net/paste/results/NOVfUe55.html
    If you are going to use STL vectors you need to use them as a C array/pointer for OpenGL to use it.

  4. #4
    Senior Member Regular Contributor songho's Avatar
    Join Date
    May 2003
    Location
    Canada
    Posts
    242

    Re: glBuild2DMipmaps

    I think the crash came from the second last line:
    free( &cData );

    You cannot deallocate the vector with free(). (It must be a pair, malloc-free.) Indeed, it will be automatically destructed when the function exits. Just remove the above line.

    And, since C++ vector class is also a contiguous memory, you can use it as C-style array in a way. The last param of gluBuild2DMipmaps() would be:
    &cData[0].

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: glBuild2DMipmaps

    No songho. vector is a class that can have more than a single member inside it. If this is the case (and it is implementation dependant to do so), he simply cannot do it like that.
    More, nothing, from what I know at least, can say all the elements in vector are contiguous in memory, it depends on the type of allocator, so doing &(*cData.begin()) wouldn't be of help neither.

    But you are right for free (&cData).

  6. #6
    Senior Member Regular Contributor songho's Avatar
    Join Date
    May 2003
    Location
    Canada
    Posts
    242

    Re: glBuild2DMipmaps

    jide,
    I don't quite follow what you meant. C++ vector class is a data structure with _contiguous_ memory location. All elements in the vector container are stored one after the other. So, you can directly access any elements via the subscript operator [] same as conventional array does.

    My point was: use the address where the data actually starts from, not the address of the vector object.

    I reviewed Jameson Quave's codes, and found out he stores struct variables(ColorRGB) into the vector container. Eek! I missed this part. I thought he stores GLubyte data into the vector. However, &cData[0] is still _okay_ in memory-wise, because his struct has only 3 members (its size is 3 bytes).

    Although, it must be casted to (GLubyte*). The compiler should stop at that point and notify the type-conversion error.

    It is a _bad_ casting, but it should work with:
    static_cast<GLubyte*>&cData[0]

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,042

    Re: glBuild2DMipmaps

    songho is right, using &cData[0] should work just fine.
    GLIM - Immediate Mode Emulation for GL3

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: glBuild2DMipmaps

    Yes you're right. I was persuaded nothing could tell if all elements of a std::vector are contiguous or not in memory. Anyway &cData[0] is the right form but not &cData.

  9. #9
    Junior Member Newbie
    Join Date
    May 2006
    Location
    Louisiana
    Posts
    12

    Re: glBuild2DMipmaps

    well i went another route since many coders disagreed with the idea of using vector's for this, and just used a few simple arrays... it was simpler and turned out to work... thanks for the advice

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