This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Opening a window via a c program problem


When I wrote this program it compilied fine for B18. So 
when I updated to 19.1 I tried to compile it again but now 
I get a warning when I compile - main function isn't an int.
But that's the only problem when I compile using the 
makefile also listed below. But it won't run anymore!

I think I have narrowed the problem down to the commands 
for opening another window under glut.h, can anyone help 
with this problem or is there away around it?

I am trying to compile the program down below on windows 95 using gcc 19.1 and it compiles with no errors:

/* Rotating cube with color interpolation */

/* Demonstration of use of homogeneous coordinate 
transformations and simple data structure for representing
cube from Chapter 4 */

/*Both normals and colors are assigned to the vertices */
/*Cube is centered at origin so (unnormalized) normals
are the same as the vertex values */

#include <stdlib.h>
#include <GL/glut.h>


	GLfloat vertices[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0},
	{1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, 
	{1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}};

	GLfloat normals[][3] = {{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0},
	{1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, 
	{1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}};

	GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0},
	{1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, 
	{1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};

void polygon(int a, int b, int c , int d)
{

/* draw a polygon via list of vertices */

 	glBegin(GL_POLYGON);
		glColor3fv(colors[a]);
		glNormal3fv(normals[a]);
		glVertex3fv(vertices[a]);
		glColor3fv(colors[b]);
		glNormal3fv(normals[b]);
		glVertex3fv(vertices[b]);
		glColor3fv(colors[c]);
		glNormal3fv(normals[c]);
		glVertex3fv(vertices[c]);
		glColor3fv(colors[d]);
		glNormal3fv(normals[d]);
		glVertex3fv(vertices[d]);
	glEnd();
																										}

void colorcube(void)
{

/* map vertices to faces */

	polygon(0,3,2,1);
	polygon(2,3,7,6);
	polygon(0,4,7,3);
	polygon(1,2,6,5);
	polygon(4,5,6,7);
	polygon(0,1,5,4);
}

static GLfloat theta[] = {0.0,0.0,0.0};
static GLint axis = 2;

void display(void)
{
/* display callback, clear frame buffer and z buffer,
   rotate cube and draw, swap buffers */

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glRotatef(theta[0], 1.0, 0.0, 0.0);
	glRotatef(theta[1], 0.0, 1.0, 0.0);
	glRotatef(theta[2], 0.0, 0.0, 1.0);

 colorcube();

 glFlush();
	glutSwapBuffers();
}

void spinCube()
{

/* Idle callback, spin cube 2 degrees about selected axis */

	theta[axis] += 2.0;
	if( theta[axis] > 360.0 ) theta[axis] -= 360.0;
	display();
}

void mouse(int btn, int state, int x, int y)
{

/* mouse callback, selects an axis about which to rotate */

	if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN) axis = 0;
	if(btn==GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) axis = 1;
	if(btn==GLUT_RIGHT_BUTTON && state == GLUT_DOWN) axis = 2;
}

void myReshape(int w, int h)
{
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    if (w <= h)
        glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
            2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
    else
        glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
            2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
    glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);

/* need both double buffering and z buffer */

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutCreateWindow("colorcube");
    glutReshapeFunc(myReshape);
    glutDisplayFunc(display);
	   glutIdleFunc(spinCube);
	   glutMouseFunc(mouse);
	   glEnable(GL_DEPTH_TEST); /* Enable hidden--surface--removal */
    glutMainLoop();
}

This is the makefile i am using:


#---------------------------------------------------------------------------
# Cygnus Win32 (gcc based)
#
GRAPHICS_LIBS = -lglut -lglu32 -lopengl32 -luser32 -lgdi32 
FG_CFLAGS = $(GLOBAL_CFLAGS) -DWIN32 -DUSE_RAND
#---------------------------------------------------------------------------

cube.exe: cube.o
	$(CC) -o cube.exe cube.o  $(GRAPHICS_LIBS)
cube.o: cube.c
	$(CC) $(FG_CFLAGS) $(INCLUDES) -c cube.c -o $@



But when I try to run it I get errors:

(C:\FREEGL\CUBE\CUBE.EXE 1037) Exception trapped!
(C:\FREEGL\CUBE\CUBE.EXE 1037) exception C0000005 at 40188A
(C:\FREEGL\CUBE\CUBE.EXE 1037) exception: ax 0 bx 255FB8C cx 255FAE4 dx 0
(C:\FREEGL\CUBE\CUBE.EXE 1037) exception: si 255FC98 di 8014DF54 bp 255FAD8 sp 255FAD4
(C:\FREEGL\CUBE\CUBE.EXE 1037) exception is: STATUS_ACCESS_VIOLATION
(C:\FREEGL\CUBE\CUBE.EXE 1037) Stack trace:
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 0: sp = 0x255F7E8, pc = 0x1000A250
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 1: sp = 0x255F90C, pc = 0xBFF76841
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 2: sp = 0x255F930, pc = 0xBFF86FDB
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 3: sp = 0x255F9C4, pc = 0xFFECBAD7
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 4: sp = 0x255FAD8, pc = 0x4020AC
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 5: sp = 0x255FB38, pc = 0x402725
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 6: sp = 0x255FB6C, pc = 0x4014DD
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 7: sp = 0x255FB78, pc = 0x10006B89
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 8: sp = 0x255FE0C, pc = 0x10006B9C
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 9: sp = 0x255FE18, pc = 0x41DE5E
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 10: sp = 0x255FE28, pc = 0x40103A
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 11: sp = 0x255FE38, pc = 0xBFF8A552
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 12: sp = 0x255FF78, pc = 0xBFF8A404
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 13: sp = 0x255FFF4, pc = 0xBFF88DC7
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 14: sp = 0x82DDBFEC, pc = 0xC00777C1
(C:\FREEGL\CUBE\CUBE.EXE 1037) frame 15: sp = 0xC5DA7DB0, pc = 0x3137
(C:\FREEGL\CUBE\CUBE.EXE 1037) End of stack trace (more stack frames may be present)


Any help would be appreciated, thanks.Paul

----------------------
Paul Richardson
par297@soton.ac.uk

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]