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

Thread: New to Opengl, having trouble with program.

  1. #1
    Newbie Newbie
    Join Date
    Jul 2013
    Posts
    2

    New to Opengl, having trouble with program.

    I just started working with openGL a few days ago, but my first foray into using VBOs has encountered a strange error that I haven't found searching the forums or the internet yet, the code below throws an error when I try to run it, "Unhandled exception at 0x7732BDA1 in Project6.exe: 0xC0000005: Access violation executing location 0x00000000."
    Code :
    #include <glew.h>
    #include <freeglut.h>
    #include <iostream>
     
    using namespace std;
    #define GLEW_STATIC
    void init (int argc, char** argv)
    {
    	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    	glutInitWindowSize (1920,1080);
    	glutCreateWindow ("OpenGL happens here.");
     
    	glClearColor (0.0, 0.0, 0.0, 0.0);
    	glMatrixMode (GL_PROJECTION); 
    	glLoadIdentity ();
    	glOrtho (-1 * (1920/2), 1920/2, -540, 540, -1.0, 1.0); 
    }
    int main (int argc, char** argv) 
    {
    	glutInit (&argc, argv);
    	glewInit();
    	wglGetProcAddress;
    	static const GLsizeiptr PositionSize = 6 * 2 * sizeof(GLfloat);
    	static const GLfloat PositionData[] = 
    	{
    		-100.0,-100.0,
    		100.0,-100.0,
    		100.0,100.0,
    		100.0,100.0,
    		-100.0,100.0,
    		-100.0,-100.0
    	};
    	static const GLsizeiptr ColorSize = 6 * 3 * sizeof(GLubyte);
    	static const GLubyte ColorData[] =
    	{
    		255,0,0,
    		255,255,0,
    		0,255,0,
    		0,255,255,
    		0,255,0,
    		255,255,0
    	};
    	glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    	glutInitWindowSize (1920,1080);
    	GLuint vboid;
    	glGenBuffers(1, &vboid);
    	init(argc, argv);
    }

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    716
    You are calling glewInit() before glutCreateWindow (which is the function that creates the OpenGL context), however, GLEW requires a valid OpenGL context to be able to query extensions.

    BTW, this line:

    Code :
    wglGetProcAddress;

    does nothing.

  3. #3
    Newbie Newbie
    Join Date
    Jul 2013
    Posts
    2
    Quote Originally Posted by carsten neumann View Post
    You are calling glewInit() before glutCreateWindow (which is the function that creates the OpenGL context), however, GLEW requires a valid OpenGL context to be able to query extensions.

    BTW, this line:

    Code :
    wglGetProcAddress;

    does nothing.
    Thanks, that fixed that error, and now everything runs and compiles but fails to render anything when it runs using this updated code (With a bunch more changes besides your suggestions as well.):

    Code :
    #include <glew.h>
    #include <freeglut.h>
    #include <iostream>
     
    using namespace std;
    #define GLEW_STATIC
     
    static GLuint vboid;
     
    static const GLsizeiptr PositionSize = 6 * 3 * sizeof(GLfloat);
    static const GLfloat PositionData[] = 
    {
    	-100.0,-100.0,0.0,
    	100.0,-100.0,0.0,
    	100.0,100.0,0.0,
    	100.0,100.0,0.0,
    	-100.0,100.0,0.0,
    	-100.0,-100.0,0.0
    };
    void Disp ()
    {
    	glVertexPointer(3, GL_FLOAT, 0, NULL);
    	glBindBuffer(GL_ARRAY_BUFFER, vboid);
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glDrawArrays(GL_TRIANGLES, 0, sizeof(GLfloat) * 18);
    	glFlush();
    }
    void init (int argc, char** argv)
    {
    	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    	glutInitWindowSize (1920,1080);
    	glutCreateWindow ("OpenGL happens here.");
     
    	glClearColor (0.0, 0.0, 0.0, 0.0);//sets the background to black
    	glMatrixMode (GL_PROJECTION); //Does something we don't understand
    	glLoadIdentity ();
    	glOrtho (-1 * (1920/2), 1920/2, -540, 540, -1.0, 1.0); //Sets up da graph stuff
    	glutDisplayFunc(Disp);
    }
    int main (int argc, char** argv)
    {
    	glutInit (&argc, argv);
    	init(argc, argv);
    	glewInit();
    	glGenBuffers(1, &vboid);
    	glBindBuffer(GL_ARRAY_BUFFER, vboid);
    	//glBufferData(GL_ARRAY_BUFFER, sizeof(ColorSize), ColorData, GL_STATIC_DRAW);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(PositionSize), PositionData, GL_STATIC_DRAW);
    	glutMainLoop();
    }

    No errors, but nothing renders and neither gDEBugger or CodeXL can run it for some reason, the console opens and then crashes instantly when I try to use either of them.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    716
    sizeof(PositionSize) is equivalent to sizeof(GLsizeiptr), which is most likely not what you want to pass to glBufferData.

    Also, why don't you work through one of the tutorials linked from the wiki? That should give you a smoother start than trying to figuring out everything on your own.

Posting Permissions

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