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 3 of 3

Thread: okay I had it ! with this glDrawElements function!

  1. #1
    Intern Contributor
    Join Date
    Oct 2011
    Posts
    67

    okay I had it ! with this glDrawElements function!

    I decided after a long time of trying to do a graphical user interface using just opengl graphics to go back to a gui toolkit and in the process have had to port alot of my code to win32.

    But to get too the actual problem my glDrawElement function crashes when I execute the program.

    This happens when I use anything but GL_INT for the 3rd parameter of the function and when I execute the program with GL_INT it doesn't render anything to the frustum.

    So I was trying to figure out why and I just don't understand I thought I did everything correct but I guess not....

    here is my .obj file for reference:

    Code :
    # Blender v2.61 (sub 0) OBJ File: ''
    # [url]www.blender.org[/url]
    v 1.000000 -1.000000 -1.000000
    v 1.000000 -1.000000 1.000000
    v -1.000000 -1.000000 1.000000
    v -1.000000 -1.000000 -1.000000
    v 1.000000 1.000000 -0.999999
    v 0.999999 1.000000 1.000001
    v -1.000000 1.000000 1.000000
    v -1.000000 1.000000 -1.000000
    s off
    f 1 2 3 4     
    f 5 8 7 6     
    f 1 5 6 2    
    f 2 6 7 3    
    f 3 7 8 4     
    f 5 1 4 8

    I'm using a parser I created to get the faces/vertexes in my .obj file:


    Code :
     
     char modelbuffer [20000];
      unsigned int face[3];
        ifstream file (szFileName);
     
              //While FileObject not equal end of file
              while (!file.eof() )
              {
     
                char modelbuffer[20000];
     
                file.getline(modelbuffer, 20000);
     
                switch(modelbuffer[0])
                {
     
                  cout << " " << endl;
     
                  case 'v' :
     
                  Point p;
     
                  sscanf(modelbuffer, "v %f %f %f",  &amp;p.x, &amp;p.y, &amp;p.z);
     
                  points.push_back(p);
     
                  cout << " p.x = " << p.x << " p.y = " << p.y << " p.z = " << p.x << endl;
     
                  break;
     
                  cout << " " << endl;
     
                  case 'f':
     
                  int read_count = sscanf(modelbuffer, "f %d %d %d %d", &amp;face[0], &amp;face[1], &amp;face[2],  &amp;face[3]);
     
                  cout << "face[0] = " << face[0] << " face[1] = " << face[1] << " face[2] = " << face[2] << " face[3] = " << face[3] << "\n";
     
                  if(read_count !=4)
                  {
     
                    cout << "bad/n";
                    throw std::exception();
     
                  }
     
                  faces.push_back(face[0] - 1);
                  faces.push_back(face[1] - 1);
                  faces.push_back(face[2] - 1);
                  faces.push_back(face[3] - 1);
     
                  cout << face[0] - 1 << face[1] - 1 << face[2] - 1 << face[3] - 1 << endl;
     
     
                }
     
    }
    using this struct to store the x,y,z positions also this vector was used with Point:

    Code :
    vector<Point>points;

    Code :
    struct Point 
    {
     
    float x,  y, z;
     
    };

    If someone could tell me why its not working and how to fix it that would be awesome I also provide a pastebin to the full source code if you want a closer look.

    http://pastebin.com/FsJ93ykj

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: okay I had it ! with this glDrawElements function!

    Did you try to debug your code?
    Did you try glGetError()?
    http://www.opengl.org/wiki/GL_Error_Codes

    What about this line? glGenBuffers(0, &amp;vertexbuffer);
    Is 0 valid?

    Check out the docs at http://www.opengl.org/sdk/docs/man4/
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3

Posting Permissions

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