Thread: OpenGL Stipple

  1. #1
    Registered User rogue's Avatar
    Join Date
    Oct 2005
    Posts
    9

    OpenGL Stipple

    I'm trying to stipple the red part of this tetrahedron with "fly" but the stipple doesn't show up. What am I missing?
    Code:
    #include <stdlib.h>
    #include <GL/glut.h>
    
    /* initial tetrahedron */
    
    GLfloat v[4][3]={{0.0, 0.0, 1.0}, {0.0, 0.942809, -0.33333},
          {-0.816497, -0.471405, -0.333333}, {0.816497, -0.471405, -0.333333}};
    
    GLfloat colors[4][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
                            {0.0, 0.0, 1.0}, {0.0, 0.0, 0.0}};
    
    int n;
    
    void triangle(GLfloat *va, GLfloat *vb, GLfloat *vc)
    {
    	   glVertex3fv(va);
           glVertex3fv(vb);
           glVertex3fv(vc);
    }
    
    void tetra(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *d)
    {
    		GLubyte fly[] = {
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
          0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 
          0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20, 
          0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
          0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 
          0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 
          0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
          0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 
          0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC, 
          0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
          0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 
          0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0, 
          0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08, 
          0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08};
    
    	glClear (GL_COLOR_BUFFER_BIT);
    	
        glColor3fv(colors[0]);
    	
    	glEnable (GL_POLYGON_STIPPLE);
    	glPolygonStipple (fly);	
        triangle(a, b, c);
    	
    	glDisable (GL_POLYGON_STIPPLE);
        
    	glColor3fv(colors[1]);
        triangle(a, c, d);
        
    	glColor3fv(colors[2]);
        triangle(a, d, b);
        
    	glColor3fv(colors[3]);
        triangle(b, d, c);
    }
    void mouse(int btn, int state, int x, int y)
    {
        if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)   exit(0);
    }
    void divide_tetra(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *d, int m)
    {
    
    	tetra(a,b,c,d);
    }
    
    
    void display()
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glBegin(GL_TRIANGLES);
        divide_tetra(v[0], v[1], v[2], v[3], n);
        glEnd();
        glFlush();
    }
    
    
    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);
        glutPostRedisplay();
    }
    void init (void) 
    {
       glClearColor (0.0, 0.0, 0.0, 0.0);
       glShadeModel (GL_FLAT);    
    }
    
    
    void main(int argc, char **argv)
    {
    
        n=4; /* or enter number of subdivision steps here */
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(800, 600);
        glutCreateWindow("3D TetraHedron");
    	init ();
        glutReshapeFunc(myReshape);
    	glutMouseFunc (mouse);
        glutDisplayFunc(display);
        glEnable(GL_DEPTH_TEST);
        glClearColor (1.0, 1.0, 1.0, 1.0);
        glutMainLoop();
    }
    Thanks
    Rogue

  2. #2
    Registered User rogue's Avatar
    Join Date
    Oct 2005
    Posts
    9
    No replies?
    Surely someone knows whats going on?

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Maybe you would get better results on the game programming board. Also bumping threads is a little rude.
    Woop?

  4. #4
    Registered User rogue's Avatar
    Join Date
    Oct 2005
    Posts
    9
    Code:
    
    
    #include <stdlib.h>
    #include <GL/glut.h>
    
    /* initial tetrahedron */
    
    GLfloat v[4][3]={{0.0, 0.0, 1.0}, {0.0, 0.942809, -0.33333},
          {-0.816497, -0.471405, -0.333333}, {0.816497, -0.471405, -0.333333}};
    
    GLfloat colors[4][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
                            {0.0, 0.0, 1.0}, {0.0, 0.0, 0.0}};
    
    int n;
    
    	GLubyte fly[] = {								//fly stipple pattern
          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
          0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 
          0x04, 0x60, 0x06, 0x20, 0x04, 0x30, 0x0C, 0x20, 
          0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
          0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 
          0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 
          0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
          0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 
          0x66, 0x01, 0x80, 0x66, 0x33, 0x01, 0x80, 0xCC, 
          0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
          0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 
          0x03, 0x31, 0x8c, 0xc0, 0x03, 0x33, 0xcc, 0xc0, 
          0x10, 0x63, 0xC6, 0x08, 0x10, 0x30, 0x0c, 0x08, 
          0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08};
    
    
    void triangle(GLfloat *va, GLfloat *vb, GLfloat *vc)
    {
           glVertex3fv(va);
           glVertex3fv(vb);
           glVertex3fv(vc);
    }
    
    void tetra(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *d)
    {
    
    	glColor3fv(colors[0]);//sets color to red
        glEnable (GL_POLYGON_STIPPLE);//sets to enable polygon stipple
    	glPolygonStipple (fly);//sets the polygon stipple to fly[]
    
    	glBegin(GL_POLYGON);//starts the polygon draw, has to be polygon so polygon stipple will work
    
    	glVertex2fv(v[0]);
    	glVertex2fv(v[1]);
    	glVertex2fv(v[2]);
    
    	glEnd();//ends polygon
    	glDisable (GL_POLYGON_STIPPLE);//ends the stipple
    
    	glBegin(GL_TRIANGLES);//starts triangles
    
    	glColor3fv(colors[1]);
        triangle(a, c, d);
        glColor3fv(colors[2]);
        triangle(a, d, b);
        glColor3fv(colors[3]);
        triangle(b, d, c);
    
    	glEnd();
    	
    }
    
    void divide_tetra(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *d, int m)
    {
    
        //GLfloat mid[6][3];
        
        tetra(a,b,c,d); //calls the tetra draw function
    }
    
    void mouse(int btn, int state, int x, int y)//function that exits upon right mouse button in down state
    {
        if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)   exit(0);
    }
    
    
    void display()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        divide_tetra(v[0], v[1], v[2], v[3], n);
        
        glFlush();
    }
    
    
    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);
        glutPostRedisplay();
    }
    
    
    void main(int argc, char **argv)
    {
        n=4; /* or enter number of subdivision steps here */
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(500, 500);
        glutCreateWindow("Attack of the fly Tetrahedron!!");
        glutReshapeFunc(myReshape);
    	glutMouseFunc (mouse);//This function calls mouse which closes upon clicking right mouse button
        glutDisplayFunc(display);
        glEnable(GL_DEPTH_TEST);
        glClearColor (1.0, 1.0, 1.0, 1.0);
        glutMainLoop();
    }

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    You don't need to post the code twice. Bumping is frowned on. Please try posting in the gamedevelopment forum.

  6. #6
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Same code alright - just some things in it are redone. Possibly for speed.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    main returns int.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 07:57 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM