V
V
VladBond2017-10-31 19:30:28
OpenGL
VladBond, 2017-10-31 19:30:28

How to shade a shape in OpenGl?

Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glLoadIdentity();
            Gl.glColor3f( 0.0f, 1.0f, 1.0f);
            Gl.glBegin(Gl.GL_QUAD_STRIP);

            Gl.glVertex2f(-160, 160);
            Gl.glVertex2f(-160, -160);
            Gl.glVertex2f(-80, 80);
            Gl.glVertex2f(-80, -80);

            
            Gl.glVertex2f(-160, 160);
            Gl.glVertex2f(-80, 80);
            Gl.glVertex2f(160, 160);
            Gl.glVertex2f(80, 80);

            
            Gl.glVertex2f(160, 160);
            Gl.glVertex2f(80, 80);
            Gl.glVertex2f(160, -160);
            Gl.glVertex2f(80, -80);

            
            Gl.glVertex2f(-160, -160);
            Gl.glVertex2f(80, -80);
            Gl.glVertex2f(-160, 160);
            Gl.glVertex2f(-80, -80);


            

            
            Glubyte[] s =
            {
                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0xFF, 0xFF, 0xFF,

                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0xFF, 0xFF, 0xFF,

                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0xFF, 0xFF, 0xFF,

                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0x18, 0x01, 0x81,
                0xFF, 0xFF, 0xFF, 0xFF,    
            };


            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,
                0x06, 0x64, 0x26, 0x60,
                0x0c, 0xcc, 0x33, 0x30,
                0x18, 0xcc, 0x33, 0x18,
                0x10, 0xc4, 0x23, 0x08,
                0x10, 0x63, 0xC6, 0x08,
                0x10, 0x30, 0x0c, 0x08,
                0x10, 0x18, 0x18, 0x08,
                0x10, 0x00, 0x00, 0x08
            };


            Gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
            Gl.glColor3f(1.0f, 0.0f, 0.0f);
            
            Gl.glPolygonStipple(s);
            Gl.glEnable(Gl.GL_POLYGON_STIPPLE);

            Gl.glFlush();
            AnT.Invalidate();
            Gl.glEnd();
It is necessary to solve the laboratory work with the task: to shade the rectangles using your own array (well, approximately)))
But I can’t. The shape should retain its original color.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question