2 Replies - 1576 Views - Last Post: 24 February 2011 - 08:56 PM Rate Topic: -----

#1 ghillieLEAD  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 208
  • Joined: 08-March 10

OpenGL Access Violation First Program

Posted 24 February 2011 - 07:00 PM

I'm trying to get started using OpenGL rather than just SDL and am having a spot of trouble getting my first program to run. The following code compiles and links fine, but when I run the program I get an access violation error.

#include <Windows.h>
#include <gl\GL.h>
#include "SDL.h"

int main(int argc, char* argv[])
{
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);

	SDL_Init(SDL_INIT_VIDEO);
	SDL_SetVideoMode(900, 600, 0, SDL_OPENGL | SDL_HWSURFACE | SDL_NOFRAME);

	glViewport(0, 0, 900, 600);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0);
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glMatrixMode(GL_PROJECTION);
	glMatrixMode(GL_MODELVIEW);

	SDL_Quit();
	return 0;
}



The exact error message I am getting when I run the program is this, "Unhandled exception at 0x6812a8b9 in OpenGL.exe: 0xC0000005: Access violation writing location 0x00000160."

What's the issue?

This post has been edited by ghillieLEAD: 24 February 2011 - 07:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL Access Violation First Program

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: OpenGL Access Violation First Program

Posted 24 February 2011 - 08:42 PM

You may need to call SDL_Init first.

#include <Windows.h>
#include <gl\GL.h>
#include "SDL.h"

int main(int argc, char* argv[])
{
	SDL_Init(SDL_INIT_VIDEO);

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);

	SDL_SetVideoMode(900, 600, 0, SDL_OPENGL | SDL_HWSURFACE | SDL_NOFRAME);

	glViewport(0, 0, 900, 600);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0);
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glMatrixMode(GL_PROJECTION);
	glMatrixMode(GL_MODELVIEW);

	SDL_Quit();
	return 0;
}


Was This Post Helpful? 1
  • +
  • -

#3 ghillieLEAD  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 208
  • Joined: 08-March 10

Re: OpenGL Access Violation First Program

Posted 24 February 2011 - 08:56 PM

That did it. Thanks much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1