Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Access Violation GLEW/GLFW3

  1. #11
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by doctorzeus View Post
    Code :
            std::vector<float> vertexPoints, normalsPoints, texturePoints;
            const float GetVertexesFront()
    	{
    		return vertexPoints.front();
    	}
    };
    The above returns a copy of the first element in the vector. You want to return (and store) either a reference or pointer to the first element in the vector. The fact that this isn't immediately obvious to you indicates that you're still at a very early stage in learning C++. You need to learn C++ first before you start trying to learn how to use OpenGL (or anything else) in a C++ program.

  2. #12
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    791
    Hmm, this is moving off-topic and into how pointers, memory, and object life time in C++ work and I really think you'd make your life easier if you'd review those issues outside of your concrete problem. Graphics programming is to a good extent about managing the memory for your assets.

    The front() function for std::vector returns (a reference to) the first element in the vector which you then assign to the local variable verteciesFront. You then pass the address of that local variable to glVertexPointer, which is very different from passing the address of the first element in the vector.

  3. #13
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by GClements View Post
    The above returns a copy of the first element in the vector. You want to return (and store) either a reference or pointer to the first element in the vector. The fact that this isn't immediately obvious to you indicates that you're still at a very early stage in learning C++. You need to learn C++ first before you start trying to learn how to use OpenGL (or anything else) in a C++ program.
    Well keeping in mind at that stage I had been up for the last 48 hours..

  4. #14
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by carsten neumann View Post
    Hmm, this is moving off-topic and into how pointers, memory, and object life time in C++ work and I really think you'd make your life easier if you'd review those issues outside of your concrete problem. Graphics programming is to a good extent about managing the memory for your assets.

    The front() function for std::vector returns (a reference to) the first element in the vector which you then assign to the local variable verteciesFront. You then pass the address of that local variable to glVertexPointer, which is very different from passing the address of the first element in the vector.
    I have been reviewing it since you suggested it, it has been a while since I have had to do memory management properly..

    I changed it to this:

    Code :
    float *GetVertexVectorPoint()
    	{
    		return &vertexPoints[0];
    	}

    Many Thanks!

    DoctorZeus
    Last edited by doctorzeus; 08-09-2013 at 07:03 AM.

  5. #15
    Newbie Newbie
    Join Date
    Dec 2013
    Posts
    1
    Hi Alfonse Reinheart...could you help me please! I've been stuck on this for hours...I'm having the same access violation when calling glGenbuffers. I made sure I followed these steps exactly (initializing glfw, setting window properties, then creating the window before glew calls) and what I've done is in line with everything else I've found online. I'm rather new to openGL so I'm really lost as to what could be going wrong.

    This is how I've written it:
    glfwInit();
    glewExperimental = GL_TRUE;
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(1200, 800, "Game", nullptr, nullptr); // Windowed

    glewInit();


    typedef void(*GENBUFFERS) (GLsizei, GLuint*);

    // Load address of function and assign it to a function pointer
    GENBUFFERS glGenBuffers = (GENBUFFERS)wglGetProcAddress("glGenBuffers");

    // Call function as normal
    GLuint vertexBuffer;
    glGenBuffers(1, &vertexBuffer);

    printf("%u\n", vertexBuffer);

    Any help would be greatly appreciated!

Posting Permissions

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