OpenGL Problem

I have a problem with some Code i was working on.

the Errors are



1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\glaux.h(17): warning C4068: unknown pragma
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\glaux.h(374): warning C4068: unknown pragma
1>c:\users\josh\documents\visual studio 2010\projects\glopen_game\glopen_game\main.cpp(50): warning C4789: destination of memory copy is too small
1>c:\users\josh\documents\visual studio 2010\projects\glopen_game\glopen_game\main.cpp(51): warning C4789: destination of memory copy is too small
1>c:\users\josh\documents\visual studio 2010\projects\glopen_game\glopen_game\main.cpp(69): warning C4789: destination of memory copy is too small

and then it exits with 0x1


[\code]

the Code is


#include <cstdlib>
#include <gl\glut.h>
#include <gl\GLAUX.H>
#include <iostream>
#include <ctime>
using namespace std;
// Particle Shape
float partShape[4] = {-5, -5, 5, 5};
// Particle Position
float partPosition[4] = {0, 0, 0, 0};
// Particle Spin
float Spin = 0.0;
// Box Position (for Physics)
float Position[1] = {0};
// Operation Interval 1/60th of a second
float Interval = (1 / 60);
float mouseX = 0.0;
float mouseY = 0.0;

// Random number
int Rnd(int Min, int Max)
{
	int Random;
	int Range(Max - Min);
	Random = Min+int(Range*rand()/(RAND_MAX + 1));
	return Random;
}

void drawBox(void)
{
	// Drawing the Box
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();
		glRotatef(Spin, 0, 0, 0);
		glRectf(partPosition[1],partPosition[2],partPosition[3],partPosition[4]);
	glPopMatrix();
	glFlush();
	glutSwapBuffers();
}
void initDraw()
{
	//Spinning of the Box
	Spin += Rnd(-2, 2);
	if(Spin >= 360)
		Spin = 0;
	if(Spin <= -360)
		Spin = 0;
	drawBox();
	// Falling of the Box
	Position[1] = mouseX;
	Position[1] -= (9.81 / Interval);
}

void bufferClearInit(void)
{
	// Sets Clear Buffer for Colour and Depth
	glClearColor(1, 1, 1, 1);
	glClearDepth(0);
}
void MouseFunc(int button, int state, int x, int y)
{
	if((button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN))
	{
		mouseX = x;
		mouseY = y;
		partPosition[1] = partShape[1] + x;
		partPosition[2] = partShape[2] + y;
		partPosition[3] = partShape[3] + x;
		partPosition[4] = partShape[4] + y;
		glutIdleFunc(initDraw);
	}
	if((button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN))
	{
		glutIdleFunc(initDraw);
	}
}
int main(int argc, char** argv)
{
	// Window Settings
	glutInitWindowPosition(300,100);
	glutInitWindowSize(400,800);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInit(&argc, argv);
	glutCreateWindow("Boxes");
	bufferClearInit();
	// Mouse Functions
	glutMouseFunc(MouseFunc);
	glutMainLoop();
}
[\code]

don’t use glaux ! it’s really old and not maintained since many years ! Plus, the code you did, doesn’t need glaux at all.

i forgot to remove the header but that has been edited out. but the problem continues.

now it’s only

1>c:\users\josh\documents\visual studio 2010\projects\glopen_game\glopen_game\main.cpp(49): warning C4789: destination of memory copy is too small
1>c:\users\josh\documents\visual studio 2010\projects\glopen_game\glopen_game\main.cpp(50): warning C4789: destination of memory copy is too small
1>c:\users\josh\documents\visual studio 2010\projects\glopen_game\glopen_game\main.cpp(68): warning C4789: destination of memory copy is too small

main.cpp(49): warning C4789: destination of memory copy is too small

This is a C issue, not OpenGL. Have a deeper look at your code to find the error.

PS: between, these are not errors but warnings.

These are just warnings. Your code should run fine. What are u trying to do by the way? You have not setup ur modelview/projection matrices.

it compiles but then it jsut closes down randomly and it’s a 2d box that spawns where you click and falls down off screen.

You should not hook the idle func each click. like the mouse func. hook the idle func. in main. If u want to call your drawing func, use glutPostRedisplay.

float Position[1] = {0};

This array has only one element in it, but yet…

	Position[1] = mouseX;
	Position[1] -= (9.81 / Interval);

You’re setting the second element here. You’re also using partPosition (float partPosition[4] = {0, 0, 0, 0}:wink: wrongly:

glRectf(partPosition[1],partPosition[2],partPosition[3],partPosition[4]);

And both partPosition and partShape (float partShape[4] = {-5, -5, 5, 5}:wink: here:

		partPosition[1] = partShape[1] + x;
		partPosition[2] = partShape[2] + y;
		partPosition[3] = partShape[3] + x;
		partPosition[4] = partShape[4] + y;

I haven’t looked elsewhere in your code for other similar mistakes.

Arrays in C/C++ are 0-based, not 1-based. An array with 4 elements (float partPosition[4]) should index them as 0 to 3 (partPosition[0], partPosition[1], partPosition[2], partPosition[3]), not 1 to 4 (partPosition[1], partPosition[2], partPosition[3], partPosition[4]). You’ve basically got buffer overflows all over your code.

Okay well thanks on the Array, It’s clear in my head now but the worst part is…

Now I’m getting no errors and the same thing is happening… it runs openGL then text appears in the C++ window and closes down… all i can see id the word Debug before it closes.

Could u try and make glutInit(&argc, argv); the first line of main.

Nope

Could u post the whole code now after the changes?
One more thing, could u tell me
the compiler u r using,
the glut version u r using,
anything else that may be useful

GLUT 3.7
Microsoft Visual C++ Express 2010

#include <cstdlib>
#include <gl\glut.h>
#include <iostream>
#include <ctime>
using namespace std;
// Particle Shape
int partShape[4] = {-5, -5, 5, 5};
// Particle Position
int partPosition[4] = {0, 0, 0, 0};
// Particle Spin
int Spin = 0;
// Box Position (for Physics)
float Position[2] = {0, 0};
// Operation Interval 1/60th of a second
float Interval = (1 / 60);
int mouseX = 0;
int mouseY = 0;

// Random number
int Rnd(int Min, int Max)
{
	int Random;
	int Range(Max - Min);
	Random = Min+int(Range*rand()/(RAND_MAX + 1));
	return Random;
}

void drawBox(void)
{
	// Drawing the Box
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POLYGON);
		glRotatef(Spin, 0, 0, 0);
		glRectf(partPosition[0],partPosition[1],partPosition[2],partPosition[3]);
	glEnd();
	glFlush();
	glutSwapBuffers();
}
void initDraw()
{
	//Spinning of the Box
	Spin += Rnd(-2, 2);
	if(Spin >= 360)
		Spin = 0;
	if(Spin <= -360)
		Spin = 0;
	drawBox();
	// Falling of the Box
	Position[0] = mouseX;
	Position[0] -= (9.81 / Interval);
	partPosition[0] -= Position[0]; //X1
	partPosition[2] -= Position[0]; //X2
	partPosition[1] -= Position[1]; //Y1
	partPosition[3] -= Position[1]; //Y2
}

void bufferClearInit(void)
{
	// Sets Clear Buffer for Colour and Depth
	glClearColor(1, 1, 1, 1);
	glClearDepth(0);
}
void MouseFunc(int button, int state, int x, int y)
{
	if((button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN))
	{
		mouseX = x;
		mouseY = y;
		partPosition[0] = partShape[0] + x;
		partPosition[1] = partShape[1] + y;
		partPosition[2] = partShape[2] + x;
		partPosition[3] = partShape[3] + y;
		glutIdleFunc(initDraw);
	}
	if((button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN))
	{
		glutIdleFunc(initDraw);
	}
}
int main(int argc, char** argv)
{
	// Window Settings
	glutInit(&argc, argv);
	bufferClearInit();
	glutInitWindowPosition(300,100);
	glutInitWindowSize(400,800);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutCreateWindow("Boxes");
	glutIdleFunc(initDraw);
	// Mouse Functions
	glutMouseFunc(MouseFunc);
	glutMainLoop();
}

Have you run this in the debugger?

?

'glOpen_Game.exe': Loaded 'C:\Users\Josh\Documents\Visual Studio 2010\Projects\glOpen_Game\Release\glOpen_Game.exe', Symbols loaded.
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64
tdll.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\opengl32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\glu32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\ddraw.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\dciman32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\setupapi.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\devobj.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\glut32.dll', Binary was not built with debug information.
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\winmm.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\msvcr100.dll', Symbols loaded.
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\atiglpxx.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\atioglxx.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\ws2_32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64
si.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\atigktxx.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\aticfx32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\atiadlxy.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\wintrust.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file
'glOpen_Game.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll', Cannot find or open the PDB file
The program '[2176] glOpen_Game.exe: Native' has exited with code 1 (0x1).
'glOpen_Game.exe': Loaded 'C:\Users\Josh\Documents\Visual Studio 2010\Projects\glOpen_Game\Release\glOpen_Game.exe', Symbols loaded.

You are compiling your program in release mode, so no debugging information is available with the compiled code. Compile your code in debug mode, then run the debugger on your program. But do not try to step inside a function that is included in the foreign dll’s because those will not have debugging symbol even in debugging mode.

This, precisely.

Switch to the Debug build in Configuration Manager, Ctrl-Shift-B to compile, then F5 to run it in the debugger. It should break at the point at which it’s crashing, which will tell you which line of code is causing your trouble.

It’s probably also worth while switching the Character Set from Unicode (the default in MSVC 2010) to Multi-Byte; GLUT is a really old library that predates more widespread use of Unicode so there may be interoperability problems.

it doesn’t break it just closes after the window had been initialized.

Ah i see. Call bufferClearInit() after your window is created. You are calling a gl function even before the opengl context is created.


// Window Settings
glutInit(&argc, argv);
glutInitWindowPosition(300,100);
glutInitWindowSize(400,800);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Boxes");
bufferClearInit();
//rest of the functions