Page 1 of 4 1234 LastLast
Results 1 to 10 of 31

Thread: OpenGL Problem

  1. #1
    Member Newbie
    Join Date
    Jan 2011
    Location
    Australia, Western Australia
    Posts
    37

    OpenGL Problem

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

    the Errors are
    [CODE]
    Code :
    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
    [CODE]
    Code :
    #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(&amp;argc, argv);
    	glutCreateWindow("Boxes");
    	bufferClearInit();
    	// Mouse Functions
    	glutMouseFunc(MouseFunc);
    	glutMainLoop();
    }
    [\code]

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: OpenGL Problem

    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.

  3. #3
    Member Newbie
    Join Date
    Jan 2011
    Location
    Australia, Western Australia
    Posts
    37

    Re: OpenGL Problem

    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(6: warning C4789: destination of memory copy is too small

  4. #4
    Senior Member Regular Contributor
    Join Date
    Oct 2010
    Location
    France
    Posts
    458

    Re: OpenGL Problem

    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.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: OpenGL Problem

    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.
    Regards,
    Mobeen

  6. #6
    Member Newbie
    Join Date
    Jan 2011
    Location
    Australia, Western Australia
    Posts
    37

    Re: OpenGL Problem

    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.

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: OpenGL Problem

    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.
    Regards,
    Mobeen

  8. #8
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: OpenGL Problem

    Code :
    float Position[1] = {0};
    This array has only one element in it, but yet...
    Code :
    	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} wrongly:
    Code :
    glRectf(partPosition[1],partPosition[2],partPosition[3],partPosition[4]);
    And both partPosition and partShape (float partShape[4] = {-5, -5, 5, 5} here:
    Code :
    		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.

  9. #9
    Member Newbie
    Join Date
    Jan 2011
    Location
    Australia, Western Australia
    Posts
    37

    Re: OpenGL Problem

    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.

  10. #10
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: OpenGL Problem

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

Page 1 of 4 1234 LastLast

Similar Threads

  1. OpenGL Problem
    By pczone in forum OpenGL ES
    Replies: 1
    Last Post: 06-05-2009, 09:22 AM
  2. Replies: 4
    Last Post: 09-27-2004, 06:27 AM
  3. opengl problem
    By c0mputar in forum OpenGL: User Software
    Replies: 1
    Last Post: 01-09-2004, 05:15 AM
  4. Replies: 1
    Last Post: 01-19-2003, 10:26 AM
  5. Big problem with OpenGL
    By in forum OpenGL: User Software
    Replies: 4
    Last Post: 08-09-2002, 02:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean