Article View: comp.graphics.api.opengl
Article #24Division by Zero errors?
From: mark
Date: Sun, 03 Sep 2000 19:18
Date: Sun, 03 Sep 2000 19:18
59 lines
3336 bytes
3336 bytes
Hello, I'm fairly new to OpenGL programming and am using Borland C++
Builder Pro 4. I have been getting the error "Project main.exe raised
exception class EZeroDivide with message 'Floating point division by
zero'." at various positions/orientations. The error occurs at the
command glEnd().
The only thing I can see in common is when the viewpoint is 'over' a
polygon (ie, a large polygon extending both in front of and behind the
viewpoint). If I disable lighting, everything works fine. Also, if I
disable hardware acceleration (from the Windows Control Panel) it works
fine (albeit very slowly!)
Is OpenGL supposed to cope with such polygons, or am I supposed to do
the clipping myself? Alternatively is it possibly something to do with
my card/driver? (I have a Voodoo 2 Banshee; my CPU is a K6-2). Games
such as Quake 3 run fine.
I have managed to reduce my code down to a simple example which causes
the error (width and height is normally 640x480, but changing it makes
no difference):
glEnable(GL_LIGHTING);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat light[4] = {1.0f,1.0f,1.0f,1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,light);
glLoadIdentity();
glTranslatef(-3.0f,-1.8f,-3.0f);
glNormal3f(0.0f,1.0f,0.0f);
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_POLYGON);
glVertex3f(0,0,0);
glVertex3f(0,0,16);
glVertex3f(16,0,16);
glVertex3f(16,0,0);
glEnd(); // causes error here
SwapBuffers( *hDC );
Another odd thing- if I replace glBegin(GL_POLYGON) and glEnd() with
glBegin(GL_QUADS) this example works, but if I add in a
glRotate3f(180.0f,0.0f,1.0f,0.0f); the error returns! (And if I have the
rotation with GL_POLYGON, it works also). Can anyone help?
Thanks in advance,
Mark
Technical Details
Message-ID:
<828112181348129.NC-1.33.mdwh2@news.ntlworld.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-05!sn-xit-03!supernews.com!news.gv.tsc.tdk.com!hub.org!hub.org!news.maxwell.syr.edu!newsfeed.icl.net!ayres.ftech.net!news.ftech.net!colt.net!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news2-win.server.ntlworld.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f65bb,5ef93b4ed6838474,start X-Google-Attributes: gidf65bb,public X-Google-Thread: 100291,5ef93b4ed6838474,start X-Google-Attributes: gid100291,public X-Google-ArrivalTime: 2000-09-03 12:20:00 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-05!sn-xit-03!supernews.com!news.gv.tsc.tdk.com!hub.org!hub.org!news.maxwell.syr.edu!newsfeed.icl.net!ayres.ftech.net!news.ftech.net!colt.net!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news2-win.server.ntlworld.com.POSTED!not-for-mail From: "mark" <mdwh2@NOSPAM.cheerful.com> Subject: Division by Zero errors? Message-ID: <828112181348129.NC-1.33.mdwh2@news.ntlworld.com> X-Newsreader: NewsCoaster (v1.33) [Amiga, 68k] by Mark Harman Newsgroups: comp.graphics.api.opengl,3dfx.opengl Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 60 Date: 03 Sep 2000 20:18:17 +0100 NNTP-Posting-Host: 62.253.145.8 X-Complaints-To: abuse@ntlworld.com X-Trace: news2-win.server.ntlworld.com 968008790 62.253.145.8 (Sun, 03 Sep 2000 20:19:50 BST) NNTP-Posting-Date: Sun, 03 Sep 2000 20:19:50 BST Organization: ntlworld News Service