zerebubuth n00b

Joined: 20 May 2006 Posts: 1
|
Posted: Sat May 20, 2006 2:43 pm Post subject: Weird behaviour with glPolygonMode |
|
|
On my system the following program gives some weird results:
| Code: |
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
float theta = 45.0f;
float phi = 45.0f;
void drawSphere(double radius) {
GLUquadric *quad = gluNewQuadric();
gluQuadricDrawStyle(quad, GLU_FILL);
gluSphere(quad, radius, 20, 10);
gluDeleteQuadric(quad);
}
void init() {
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);
}
void drawFilledSphere() {
// draw lines in front, black
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(0.0f, 0.0f, 0.0f);
drawSphere(1.0);
}
void drawWireframeSphere() {
// draw filled red sphere
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor3f(1.0f, 0.0f, 0.0f);
drawSphere(0.7);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(
0.0f, 0.0f, 3.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
glRotatef(theta, 1.0f, 0.0f, 0.0f);
glRotatef(phi, 0.0f, 1.0f, 0.0f);
#ifndef BROKEN
drawFilledSphere();
drawWireframeSphere();
#else
drawWireframeSphere();
drawFilledSphere();
#endif
glFlush();
glutSwapBuffers();
}
void resize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45.0f, 1.0f * w / h, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y) {
switch(key) {
case 27 :
exit(1); break;
}
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 500);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
#ifndef BROKEN
glutCreateWindow("Not Broken");
#else
glutCreateWindow("Broken");
#endif
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutReshapeFunc(resize);
init();
glutMainLoop();
return 0;
}
|
When I compile up normally it shows what I expect: a small red sphere surrounded by a larger, black, wireframe sphere. When I compile with -DBROKEN all I see is a large black sphere.
I don't know if this is because I'm using OpenGL wrong (although the problem is also in the glviewer FOX toolkit test), or because my installation, or because of my graphics card drivers (r128). Has anyone else seen these sort of problems before?
Thanks,
Zerebubuth |
|