Thread: Speeding Up Obj Loader for OpenGL

  1. #16
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96
    Quote Originally Posted by EVOEx View Post
    I was planning on looking at your code. But it's horribly unreadable, mostly due to the indentation. If you want others to read your code, make sure you indent right, at least.
    Sorry about that, i'm not really sure what the norm is with code indentation koz iv'e only ever learn't from books and iv'e never really started posting my code on the net untill recently so iv'e fallin into some bad habbits,
    As far as code indentation goes is it just bringing loops and conditionals out further then the rest of code like this

    Code:
    while()
    {
    //loop 1
                While()
                {
                //loop 2
                }
    
    }
    Or is there more to it then that?

  2. #17
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96
    Quote Originally Posted by MK27 View Post
    looks to me like you just have some vertices backward somewhere.


    Yea iv'e nailed it down to an array prob, but why would the same array work in one mode but not the other do they use differernt array formats, or have i just got the wrong number in the rendering functions somewhere?

    Quote Originally Posted by MK27 View Post
    When this happens to me, I like to pretend I am actually doing 7D graphics instead of 3D. Nothing is wrong, it's your eyes are the problem.
    What do you mean by 7D? How does that help?
    Last edited by Matty_Alan; 04-26-2010 at 12:51 AM.

  3. #18
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96
    I've just got it wokring properly it had a few major flaws; lol

    I changed:
    glDrawArrays(GL_QUADS,0, Shizzle.ArraySize) to
    glDrawArrays(GL_QUADS,0, Shizzle.ArraySize/3) to


    And
    glBufferData(GL_ARRAY_BUFFER, Temp.ArraySize, Temp.Array, GL_STATIC_DRAW);
    to:
    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*Temp.ArraySize, Temp.Array, GL_STATIC_DRAW);

    Where ArraySize is the amount of elements in the array


    However... and i bet your all pretty sick of my questions by now, lol
    If your using Glut, where would I put in the glDeleteBuffers? because i would have to break out of the main loop for that wouldn't I? unless glut has some kind of shutdown callback function I can pass by buffers to?

    Thanks for all the help anyways guys, I'm pretty happy about getting this working

  4. #19
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Matty_Alan View Post
    However... and i bet your all pretty sick of my questions by now, lol
    If your using Glut, where would I put in the glDeleteBuffers? because i would have to break out of the main loop for that wouldn't I?
    Not sure what you mean by "break out". If the program is just a GL program, all of it except for setup & initialization is inside the main loop (nb, I don't mean one long piece of spagetti). You only want to delete a buffer when you are done with the data. Eg, you have an object. Another object destroys it. Now you might as well delete the data for the destroyed object, since it will not be appearing again. I generally use global arrays to store the VBO indexes (they are just single ints, like pointers). Or more specifically arrays of structs with "VBO" members. That's how it is in the tutorial, I think, altho I don't delete anything because nothing disappears. In C++ I guess you would have arrays of objects.

    You don't need to delete the remaining buffers after the main loop is over (ie, when the program is done).

    Vis. "7D", this is only relevant if you are at least 3 meters tall. Everyone else has to google.

    Vis, your indenting, well, you have the correct idea in post #16, but what I saw first when I opened Main.cpp was this:
    Code:
    /************* DISPLAY CALLBACK FUNCTION ************/
    void Display_old(void)
    {
    glPushMatrix();
    glClear(GL_COLOR_BUFFER_BIT);
    gluLookAt(b, 0.0, a , 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    
    int a =0, b=0;
    
    
    glBegin(GL_QUADS);
    while(a < Shizzle.ArraySize)//(3*4))//Sides * (Dementions * Verticies in a quad)
    {
    glVertex3f(Shizzle.Array[a],Shizzle.Array[a+1],Shizzle.Array[a+2]);
    a= a+3;
    }
    glEnd();
    
    glutSwapBuffers();
    
    glPopMatrix();
    }
    Tch! It does get slightly better but "slightly wack" seems to be the theme:
    Code:
    void Keys(int key, int x, int y)
            {
            if(key == GLUT_KEY_UP)
    {a = a+.3;}
            if(key == GLUT_KEY_DOWN)
    {a = a-.3;}
            if(key == GLUT_KEY_LEFT)
    No, no. How about one of the following options:
    Code:
    void Keys(int key, int x, int y)
    	{
    	if(key == GLUT_KEY_UP)
    {a = a+.3;}		// not acceptable
    	if(key == GLUT_KEY_DOWN)
    		{a = a-.3;}		// acceptable
    	if(key == GLUT_KEY_LEFT) b = b+.3;	// also fine
    Oh, here's a little GL tip: it uses floats internally. With C/C++, numbers like ".3" get treated as doubles and are then converted to floats at runtime if the assignment implies this. That's not GL, that's a general principle, but it does mean you are best off indicating floats to start with if you know that's what they are going to end as (0.3f). However, that's a very minor issue, lots of people appear to care less.
    Last edited by MK27; 04-26-2010 at 08:17 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #20
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96
    Quote Originally Posted by MK27 View Post
    Not sure what you mean by "break out"
    The concept I had in my head was something like...
    I declare and load the VBO at the start of the program, however i can't delete the VBO untill glut has entered it's glutMainLoop, otherwise it wont be displayed, or it would be displayed for one frame. so anything i put after glutMainLoop() Wont happen because it's an infinate loop and by the time i terminate the program it wouldn't reach whatever comes after glutMainLoop(); which is where I would have to put the delete buffer function.


    Quote Originally Posted by MK27 View Post
    0.3f.
    Iv'e seen alot of this 'f' and 'i' in open GL, So this is just some kind of typecasting?
    Last edited by Matty_Alan; 04-26-2010 at 09:44 AM.

  6. #21
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Matty_Alan View Post
    The concept I had in my head was something like...
    I declare and load the VBO at the start of the program, however i can't delete the VBO untill glut has entered it's glutMainLoop, otherwise it wont be displayed, or it would be displayed for one frame.
    The VBO is where your object description is stored, the handle is a handle to video memory. If you delete it at any point, trying to render that object in the next frame will cause a disaster. Hence, you should only delete a buffer when the object data it contains is for an object that will no longer be displayed.

    by the time i terminate the program it wouldn't reach whatever comes after glutMainLoop(); which is where I would have to put the delete buffer function.
    Actually, any code you place in main() after glutMainLoop() will be executed when the MainLoop ends, which is when OGL is done (however you exit your app currently). But I doubt you can place OGL calls there (maybe). In any case, like I said, there is no need to delete buffers once the program is finished, they will be freed.

    Iv'e seen alot of this 'f' and 'i' in open GL, So this is just some kind of typecasting?
    I guess. It indicates something to the compiler about type, anyway. A decimal number without f is taken to be a double, with f it is taken as a float.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to use 'this' for different obj in class
    By effa in forum C++ Programming
    Replies: 2
    Last Post: 10-06-2009, 08:01 PM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. OBJ TDS files .. what are they ?
    By moonwalker in forum C++ Programming
    Replies: 1
    Last Post: 07-22-2002, 02:21 PM
  4. ARG.... My Texture Loader is screwed... PLEASE HELP!
    By minime6696 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-22-2002, 05:45 PM