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.”

#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);
}

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:


wglGetProcAddress;

does nothing.

[QUOTE=carsten neumann;1253057]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:


wglGetProcAddress;

does nothing.[/QUOTE]

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.):

#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.

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.