GLES2

Check-in [ef2f9791d8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:removed Draw*Border functions with sub functions, now implemented in Tcl.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:ef2f9791d887a7764d4532e6ef05ec74aacb1f8c
User & Date: arnulf 2013-08-31 22:32:29
Context
2013-09-01
08:46
Removed some commands. which are now implemented in Tcl. Leaf check-in: 8a246d085f user: arnulf tags: trunk
2013-08-31
22:32
removed Draw*Border functions with sub functions, now implemented in Tcl. check-in: ef2f9791d8 user: arnulf tags: trunk
11:11
fixes for 3D displaying of borders check-in: d0c312bca6 user: arnulf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/gles2Builtin.c.

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
....
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
....
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
....
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
static Tcl_ObjCmdProc Gles2_BiClearBufferCmd;
static Tcl_ObjCmdProc Gles2_BiDrawLineCmd;
static Tcl_ObjCmdProc Gles2_BiFillTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiFillTextureTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawTextureTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawRectangleBorderCmd;
static Tcl_ObjCmdProc Gles2_BiDrawDiamondBorderCmd;
static Tcl_ObjCmdProc Gles2_BiFillRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiFillTextureRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawTextureRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiSetupRenderBufferCmd;
static Tcl_ObjCmdProc Gles2_BiSetupFrameBufferCmd;
static Tcl_ObjCmdProc Gles2_BiCompileShadersCmd;
static Tcl_ObjCmdProc Gles2_BiGetFontInfoCmd;
................................................................................
	0
    },
    { "drawrectangle",
        "vertex1 vertex2 vertex3 vertex4",
        "@gles2-builtin-drawrectangle",
        Gles2_BiDrawRectangleCmd,
	0
    },
    { "drawrectangleborder",
        "box borderWidth relief shadows",
        "@gles2-builtin-drawrectangleborder",
        Gles2_BiDrawRectangleBorderCmd,
	0
    },
    { "drawdiamondborder",
        "box borderWidth relief shadows",
        "@gles2-builtin-drawdiamondborder",
        Gles2_BiDrawDiamondBorderCmd,
	0
    },
    { "filltexturerectangle",
        "vertex1 vertex2 vertex3 vertex4",
        "@gles2-builtin-filltexturerectangle",
        Gles2_BiFillTextureRectangleCmd,
	0
    },
................................................................................
//showMatrix("per1", g_Perspective);
    multiply_matrix(g_Perspective, g_ModelView, g_MVP);
//showMatrix("mul3", g_MVP);

    GL_CHECK(glUniformMatrix4fv(_projectionSlot, 1, GL_FALSE, g_MVP));
}

void LeftTopBevel(Tcl_Interp *interp, int x, int y, int width, int height, int leftBevel, char *relief, shadowColors shadow_colors) {
    GLfloat f_x;
    GLfloat f_y;
    GLfloat f_z;
    GLfloat w_diameter;
    GLfloat h_diameter;

//fprintf(stderr, "LeftTopBevel!x!%d!y!%d!width!%d!height!%d!lb!%d!relief!%s!\n", x, y, width, height, leftBevel, relief);
    f_x = Pixel2Coord(interp, x, 1);
    f_y = Pixel2Coord(interp, y, 0);
    f_z = 0.0;
//    w_radius = Pixel2Coord(interp, width/2, 1);
//    h_radius = Pixel2Coord(interp, height/2, 0);
    w_diameter = Pixel2Coord(interp, width, 1);
    h_diameter = Pixel2Coord(interp, height, 0);
//fprintf(stderr, "abs f_x!%f!f_y!%f!f_z!%f!wr!%f!hr!%f!\n", f_x, f_y, f_z, w_radius, h_radius);
//fprintf(stderr, "rel f_x!%f!f_y!%f!f_z!%f!wr!%f!hr!%f!\n", -1.0+f_x, -1.0+f_y, f_z, w_radius, h_radius);
    if (strcmp(relief, "raised") == 0) {
	if (leftBevel) {
            line_vertices[0].Position[0] = -1.0+f_x;
            line_vertices[0].Position[1] = -1.0+f_y+h_diameter/2.0;
            line_vertices[0].Position[2] = f_z;
            line_vertices[1].Position[0] = -1.0+f_x+w_diameter/2.0;
            line_vertices[1].Position[1] = -1.0+f_y+h_diameter;
            line_vertices[1].Position[2] = f_z;
//fprintf(stderr, "LTB POS1!%f!%f!%f %f!%f!%f\n", line_vertices[0].Position[0], line_vertices[0].Position[1], line_vertices[0].Position[2], line_vertices[1].Position[0], line_vertices[1].Position[1], line_vertices[1].Position[2]);

            line_vertices[0].Color[0] = shadow_colors.light_red;
            line_vertices[0].Color[1] = shadow_colors.light_green;
            line_vertices[0].Color[2] = shadow_colors.light_blue;
            line_vertices[0].Color[3] = shadow_colors.light_alpha;
            line_vertices[1].Color[0] = shadow_colors.light_red;
            line_vertices[1].Color[1] = shadow_colors.light_green;
            line_vertices[1].Color[2] = shadow_colors.light_blue;
            line_vertices[1].Color[3] = shadow_colors.light_alpha;
//fprintf(stderr, "LTB COL1!%f!%f! %f!%f!\n", line_vertices[0].Color[0], line_vertices[0].Color[1], line_vertices[0].Color[2], line_vertices[0].Color[3]);
	} else {
            line_vertices[0].Position[0] = -1.0+f_x;
            line_vertices[0].Position[1] = -1.0+f_y+h_diameter/2.0;
            line_vertices[0].Position[2] = 0.0;
            line_vertices[1].Position[0] = -1.0+f_x+w_diameter/2.0;
            line_vertices[1].Position[1] = -1.0+f_y+h_diameter;
            line_vertices[1].Position[2] = 0.0;
//fprintf(stderr, "LTB POS2!%f!%f! %f!%f!\n", line_vertices[0].Position[0], line_vertices[0].Position[1], line_vertices[1].Position[0], line_vertices[1].Position[1]);

            line_vertices[0].Color[0] = shadow_colors.dark_red;
            line_vertices[0].Color[1] = shadow_colors.dark_green;
            line_vertices[0].Color[2] = shadow_colors.dark_blue;
            line_vertices[0].Color[3] = shadow_colors.dark_alpha;
            line_vertices[1].Color[0] = shadow_colors.dark_red;
            line_vertices[1].Color[1] = shadow_colors.dark_green;
            line_vertices[1].Color[2] = shadow_colors.dark_blue;
            line_vertices[1].Color[3] = shadow_colors.dark_alpha;
//fprintf(stderr, "LTB COL2!%f!%f! %f!%f!\n", line_vertices[0].Color[0], line_vertices[0].Color[1], line_vertices[0].Color[2], line_vertices[0].Color[3]);
	}
        line_indices[0] = 0;
        line_indices[1] = 1;
    
        GL_CHECK(glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0));
        GL_CHECK(glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
            sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)));

        handleMatrices(xangle, yangle, zangle);

        GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(line_vertices), &line_vertices, GL_STATIC_DRAW));
        GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(line_indices), &line_indices, GL_STATIC_DRAW));
        GL_CHECK(glDrawElements(GL_LINES, sizeof(line_indices)/sizeof(line_indices[0]), GL_UNSIGNED_BYTE, 0));
    } else {
        if (strcmp(relief, "sunken") == 0) {
	    if (leftBevel) {
                line_vertices[0].Position[0] = -1+Pixel2Coord(interp, x, 1);
                line_vertices[0].Position[1] = -1+Pixel2Coord(interp, y, 0);
                line_vertices[0].Position[2] = -1+Pixel2Coord(interp, 0, 0);
                line_vertices[1].Position[0] = -1+Pixel2Coord(interp, x+width, 1);
                line_vertices[1].Position[1] = -1+Pixel2Coord(interp, y+width, 0);
                line_vertices[1].Position[2] = -1+Pixel2Coord(interp, 0, 0);
    
                line_vertices[0].Color[0] = shadow_colors.dark_red;
                line_vertices[0].Color[1] = shadow_colors.dark_green;
                line_vertices[0].Color[2] = shadow_colors.dark_blue;
                line_vertices[0].Color[3] = shadow_colors.dark_alpha;
                line_vertices[1].Color[0] = shadow_colors.dark_red;
                line_vertices[1].Color[1] = shadow_colors.dark_green;
                line_vertices[1].Color[2] = shadow_colors.dark_blue;
                line_vertices[1].Color[3] = shadow_colors.dark_alpha;
	    } else {
                line_vertices[0].Position[0] = -1+Pixel2Coord(interp, x, 1);
                line_vertices[0].Position[1] = -1+Pixel2Coord(interp, y, 0);
                line_vertices[0].Position[2] = -1+Pixel2Coord(interp, 0, 0);
                line_vertices[1].Position[0] = -1+Pixel2Coord(interp, x+width, 1);
                line_vertices[1].Position[1] = -1+Pixel2Coord(interp, y+width, 0);
                line_vertices[1].Position[2] = -1+Pixel2Coord(interp, 0, 0);
    
                line_vertices[0].Color[0] = shadow_colors.light_red;
                line_vertices[0].Color[1] = shadow_colors.light_green;
                line_vertices[0].Color[2] = shadow_colors.light_blue;
                line_vertices[0].Color[3] = shadow_colors.light_alpha;
                line_vertices[1].Color[0] = shadow_colors.light_red;
                line_vertices[1].Color[1] = shadow_colors.light_green;
                line_vertices[1].Color[2] = shadow_colors.light_blue;
                line_vertices[1].Color[3] = shadow_colors.light_alpha;
	    }
            line_indices[0] = 0;
            line_indices[1] = 1;
    
            GL_CHECK(glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0));
            GL_CHECK(glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
                sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)));

            handleMatrices(xangle, yangle, zangle);

            GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(line_vertices), &line_vertices, GL_STATIC_DRAW));
            GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(line_indices), &line_indices, GL_STATIC_DRAW));
            GL_CHECK(glDrawElements(GL_LINES, sizeof(line_indices)/sizeof(line_indices[0]), GL_UNSIGNED_BYTE, 0));
        } else {
#ifdef NOTDEF
            if (strcmp(relief, "ridge") == =) {
                int half;

                left = borderPtr->lightGC;
                right = borderPtr->darkGC;
ridgeGroove:
                half = width/2;
                if (!leftBevel && (width & 1)) {
	            half++;
	        }
	        XFillRectangle(display, drawable, left, x, y, (unsigned) half,
	           (unsigned) height);
	        XFillRectangle(display, drawable, right, x+half, y,
	           (unsigned) (width-half), (unsigned) height);
	    } else {
                if (stcmp(relief, "groove") == 0) {
                    left = borderPtr->darkGC;
	            right = borderPtr->lightGC;
	            goto ridgeGroove;
		} else {
                    if (strcmp(relief, "flat") == 0) {
                        XFillRectangle(display, drawable, borderPtr->bgGC, x, y,
	                  (unsigned) width, (unsigned) height);
	            } else {
                        if (strcmp(relief, "solid") == 0) {
                            UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
                            if (unixBorderPtr->solidGC == None) {
                                XGCValues gcValues;

                                gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
		                unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
		            }
		            XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
			        (unsigned) width, (unsigned) height);
			}
		    }
		}
	    }
#endif
	}
    }
}

void LeftBottomBevel(Tcl_Interp *interp, int x, int y, int width, int height, int leftBevel, char *relief, shadowColors shadow_colors) {
    GLfloat f_x;
    GLfloat f_y;
    GLfloat f_z;
    GLfloat w_diameter;
    GLfloat h_diameter;

//fprintf(stderr, "LeftBottomBevel!x!%d!y!%d!width!%d!height!%d!lb!%d!relief!%s!\n", x, y, width, height, leftBevel, relief);
    f_x = Pixel2Coord(interp, x, 1);
    f_y = Pixel2Coord(interp, y, 0);
    f_z = 0.0;
//    w_radius = Pixel2Coord(interp, width/2, 1);
//    h_radius = Pixel2Coord(interp, height/2, 0);
    w_diameter = Pixel2Coord(interp, width, 1);
    h_diameter = Pixel2Coord(interp, height, 0);
//fprintf(stderr, "abs f_x!%f!f_y!%f!f_z!%f!wr!%f!hr!%f!\n", f_x, f_y, f_z, w_radius, h_radius);
//fprintf(stderr, "rel f_x!%f!f_y!%f!f_z!%f!wr!%f!hr!%f!\n", -1.0+f_x, -1.0+f_y, f_z, w_radius, h_radius);
    if (strcmp(relief, "raised") == 0) {
	if (leftBevel) {
            line_vertices[0].Position[0] = -1.0+f_x;
            line_vertices[0].Position[1] = -1.0+f_y+h_diameter/2.0;
            line_vertices[0].Position[2] = f_z;
            line_vertices[1].Position[0] = -1.0+f_x+w_diameter/2.0;
            line_vertices[1].Position[1] = -1.0+f_y;
            line_vertices[1].Position[2] = f_z;
//fprintf(stderr, "LBB POS1!%f!%f!%f %f!%f!%f\n", line_vertices[0].Position[0], line_vertices[0].Position[1], line_vertices[0].Position[2], line_vertices[1].Position[0], line_vertices[1].Position[1], line_vertices[1].Position[2]);

            line_vertices[0].Color[0] = shadow_colors.light_red;
            line_vertices[0].Color[1] = shadow_colors.light_green;
            line_vertices[0].Color[2] = shadow_colors.light_blue;
            line_vertices[0].Color[3] = shadow_colors.light_alpha;
            line_vertices[1].Color[0] = shadow_colors.light_red;
            line_vertices[1].Color[1] = shadow_colors.light_green;
            line_vertices[1].Color[2] = shadow_colors.light_blue;
            line_vertices[1].Color[3] = shadow_colors.light_alpha;
//fprintf(stderr, "LBB COL1!%f!%f! %f!%f!\n", line_vertices[0].Color[0], line_vertices[0].Color[1], line_vertices[0].Color[2], line_vertices[0].Color[3]);
	} else {
            line_vertices[0].Position[0] = -1.0+f_x;
            line_vertices[0].Position[1] = -1.0+f_y+h_diameter/2.0;
            line_vertices[0].Position[2] = 0.0;
            line_vertices[1].Position[0] = -1.0+f_x+w_diameter/2.0;
            line_vertices[1].Position[1] = -1.0+f_y;
            line_vertices[1].Position[2] = 0.0;
//fprintf(stderr, "LBB POS2!%f!%f! %f!%f!\n", line_vertices[0].Position[0], line_vertices[0].Position[1], line_vertices[1].Position[0], line_vertices[1].Position[1]);

            line_vertices[0].Color[0] = shadow_colors.dark_red;
            line_vertices[0].Color[1] = shadow_colors.dark_green;
            line_vertices[0].Color[2] = shadow_colors.dark_blue;
            line_vertices[0].Color[3] = shadow_colors.dark_alpha;
            line_vertices[1].Color[0] = shadow_colors.dark_red;
            line_vertices[1].Color[1] = shadow_colors.dark_green;
            line_vertices[1].Color[2] = shadow_colors.dark_blue;
            line_vertices[1].Color[3] = shadow_colors.dark_alpha;
//fprintf(stderr, "LBB COL2!%f!%f! %f!%f!\n", line_vertices[0].Color[0], line_vertices[0].Color[1], line_vertices[0].Color[2], line_vertices[0].Color[3]);
	}
        line_indices[0] = 0;
        line_indices[1] = 1;
    
        GL_CHECK(glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0));
        GL_CHECK(glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
            sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)));

        handleMatrices(xangle, yangle, zangle);

        GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(line_vertices), &line_vertices, GL_STATIC_DRAW));
        GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(line_indices), &line_indices, GL_STATIC_DRAW));
        GL_CHECK(glDrawElements(GL_LINES, sizeof(line_indices)/sizeof(line_indices[0]), GL_UNSIGNED_BYTE, 0));
    } else {
        if (strcmp(relief, "sunken") == 0) {
	    if (leftBevel) {
                line_vertices[0].Position[0] = -1+Pixel2Coord(interp, x, 1);
                line_vertices[0].Position[1] = -1+Pixel2Coord(interp, y, 0);
                line_vertices[0].Position[2] = -1+Pixel2Coord(interp, 0, 0);
                line_vertices[1].Position[0] = -1+Pixel2Coord(interp, x+width, 1);
                line_vertices[1].Position[1] = -1+Pixel2Coord(interp, y+width, 0);
                line_vertices[1].Position[2] = -1+Pixel2Coord(interp, 0, 0);
    
                line_vertices[0].Color[0] = shadow_colors.dark_red;
                line_vertices[0].Color[1] = shadow_colors.dark_green;
                line_vertices[0].Color[2] = shadow_colors.dark_blue;
                line_vertices[0].Color[3] = shadow_colors.dark_alpha;
                line_vertices[1].Color[0] = shadow_colors.dark_red;
                line_vertices[1].Color[1] = shadow_colors.dark_green;
                line_vertices[1].Color[2] = shadow_colors.dark_blue;
                line_vertices[1].Color[3] = shadow_colors.dark_alpha;
	    } else {
                line_vertices[0].Position[0] = -1+Pixel2Coord(interp, x, 1);
                line_vertices[0].Position[1] = -1+Pixel2Coord(interp, y, 0);
                line_vertices[0].Position[2] = -1+Pixel2Coord(interp, 0, 0);
                line_vertices[1].Position[0] = -1+Pixel2Coord(interp, x+width, 1);
                line_vertices[1].Position[1] = -1+Pixel2Coord(interp, y+width, 0);
                line_vertices[1].Position[2] = -1+Pixel2Coord(interp, 0, 0);
    
                line_vertices[0].Color[0] = shadow_colors.light_red;
                line_vertices[0].Color[1] = shadow_colors.light_green;
                line_vertices[0].Color[2] = shadow_colors.light_blue;
                line_vertices[0].Color[3] = shadow_colors.light_alpha;
                line_vertices[1].Color[0] = shadow_colors.light_red;
                line_vertices[1].Color[1] = shadow_colors.light_green;
                line_vertices[1].Color[2] = shadow_colors.light_blue;
                line_vertices[1].Color[3] = shadow_colors.light_alpha;
	    }
            line_indices[0] = 0;
            line_indices[1] = 1;
    
            GL_CHECK(glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0));
            GL_CHECK(glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
                sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)));

            handleMatrices(xangle, yangle, zangle);

            GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(line_vertices), &line_vertices, GL_STATIC_DRAW));
            GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(line_indices), &line_indices, GL_STATIC_DRAW));
            GL_CHECK(glDrawElements(GL_LINES, sizeof(line_indices)/sizeof(line_indices[0]), GL_UNSIGNED_BYTE, 0));
        } else {
#ifdef NOTDEF
            if (strcmp(relief, "ridge") == =) {
                int half;

                left = borderPtr->lightGC;
                right = borderPtr->darkGC;
ridgeGroove:
                half = width/2;
                if (!leftBevel && (width & 1)) {
	            half++;
	        }
	        XFillRectangle(display, drawable, left, x, y, (unsigned) half,
	           (unsigned) height);
	        XFillRectangle(display, drawable, right, x+half, y,
	           (unsigned) (width-half), (unsigned) height);
	    } else {
                if (stcmp(relief, "groove") == 0) {
                    left = borderPtr->darkGC;
	            right = borderPtr->lightGC;
	            goto ridgeGroove;
		} else {
                    if (strcmp(relief, "flat") == 0) {
                        XFillRectangle(display, drawable, borderPtr->bgGC, x, y,
	                  (unsigned) width, (unsigned) height);
	            } else {
                        if (strcmp(relief, "solid") == 0) {
                            UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
                            if (unixBorderPtr->solidGC == None) {
                                XGCValues gcValues;

                                gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
		                unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
		            }
		            XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
			        (unsigned) width, (unsigned) height);
			}
		    }
		}
	    }
#endif
	}
    }
}

void VerticalBevel(Tcl_Interp *interp, int x, int y, int z, int width, int height, int depth, int leftBevel, char *relief, shadowColors shadow_colors, int side) {
    Tcl_Obj *obj;
    Tcl_Obj *cmd_obj;
    Tcl_Obj *cmd_objv[1];

//fprintf(stderr, "VerticalBevel!x!%d!y!%d!z!%d!width!%d!height!%d!depth!%d!relief!%s!\n", x, y, z, width, height, depth, relief);
    if (strcmp(relief, "raised") == 0) {
	if (leftBevel) {
            obj = BuildVertexInfo(interp, x, y, z, width, height, depth, shadow_colors.light_red,
                shadow_colors.light_green, shadow_colors.light_blue, shadow_colors.light_alpha, side);  
	} else {
            obj = BuildVertexInfo(interp, x, y, z, width, height, depth, shadow_colors.dark_red,
                shadow_colors.dark_green, shadow_colors.dark_blue, shadow_colors.dark_alpha, side);  
	}
        cmd_obj = Tcl_NewStringObj("::gles2::builtin::fillrectangle", -1);
	cmd_objv[0] = cmd_obj;
	if (Tcl_ListObjReplace(interp, obj, 0, 0, 1, cmd_objv) != TCL_OK) {
//fprintf(stderr, "VerticalBevel: cannot insert command in front of vertex info\n");
            exit(1);
	}
//fprintf(stderr, "obj!%s!\n", Tcl_GetString(obj));
        if (Tcl_EvalObjEx(interp, obj, 0) != TCL_OK) {
//fprintf(stderr, "VerticalBevel: error in executing fillrectangle command:%s\n", Tcl_GetStringResult(interp));
            exit(1);
	}
//        XFillRectangle(display, drawable,
//            (leftBevel) ? borderPtr->lightGC : borderPtr->darkGC,
//            x, y, (unsigned) width, (unsigned) height);
    } else {
        if (strcmp(relief, "sunken") == 0) {
//            XFillRectangle(display, drawable,
//               (leftBevel) ? borderPtr->darkGC : borderPtr->lightGC,
//               x, y, (unsigned) width, (unsigned) height);
	    if (leftBevel) {
                obj = BuildVertexInfo(interp, x, y, z, width, height, depth, shadow_colors.dark_red,
                    shadow_colors.dark_green, shadow_colors.dark_blue, shadow_colors.dark_alpha, side);  
	    } else {
                obj = BuildVertexInfo(interp, x, y, z, width, height, depth, shadow_colors.light_red,
                    shadow_colors.light_green, shadow_colors.light_blue, shadow_colors.light_alpha, side);  
	    }
            cmd_obj = Tcl_NewStringObj("::gles2::builtin::fillrectangle", -1);
	    cmd_objv[0] = cmd_obj;
	    if (Tcl_ListObjReplace(interp, obj, 0, 0, 1, cmd_objv) != TCL_OK) {
fprintf(stderr, "VerticalBevel: cannot insert command in front of vertex info\n");
                exit(1);
	    }
            if (Tcl_EvalObjEx(interp, obj, 0) != TCL_OK) {
fprintf(stderr, "VerticalBevel: error in executing fillrectangle command:%s\n", Tcl_GetStringResult(interp));
                exit(1);
	    }
        } else {
#ifdef NOTDEF
            if (strcmp(relief, "ridge") == =) {
                int half;

                left = borderPtr->lightGC;
                right = borderPtr->darkGC;
ridgeGroove:
                half = width/2;
                if (!leftBevel && (width & 1)) {
	            half++;
	        }
	        XFillRectangle(display, drawable, left, x, y, (unsigned) half,
	           (unsigned) height);
	        XFillRectangle(display, drawable, right, x+half, y,
	           (unsigned) (width-half), (unsigned) height);
	    } else {
                if (stcmp(relief, "groove") == 0) {
                    left = borderPtr->darkGC;
	            right = borderPtr->lightGC;
	            goto ridgeGroove;
		} else {
                    if (strcmp(relief, "flat") == 0) {
                        XFillRectangle(display, drawable, borderPtr->bgGC, x, y,
	                  (unsigned) width, (unsigned) height);
	            } else {
                        if (strcmp(relief, "solid") == 0) {
                            UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
                            if (unixBorderPtr->solidGC == None) {
                                XGCValues gcValues;

                                gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
		                unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
		            }
		            XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
			        (unsigned) width, (unsigned) height);
			}
		    }
		}
	    }
#endif
	}
    }
}

void HorizontalBevel(Tcl_Interp * interp, int x, int y, int z, int width, int height, int depth, int leftIn, int rightIn, int topBevel, char *relief, shadowColors shadow_colors, int side) {
    Tcl_Obj *obj;
    Tcl_Obj *cmd_obj;
    Tcl_Obj *cmd_objv[1];
    int x1;
    int x2;
    int x1Delta;
    int x2Delta;
    int halfway;
    int bottom;
    int topGC;
    int bottomGC;
    int myGC;
#define GC_DARK 1
#define GC_LITE 2
#define GC_BRDR 3
#define GC_BLAK 4

//fprintf(stderr, "HorizontalBevel!x!%d!y!%d!z!%d!width!%d!height!%d!depth!%d!relief!%s!leftIn!%d!rightIn!%d!\n", x, y, z, width, height, depth, relief, leftIn, rightIn);
    topGC = GC_BLAK;
    bottomGC = GC_BLAK;
    if (strcmp(relief, "raised") == 0) {
        if (topBevel) {
            topGC = GC_LITE;
            bottomGC = GC_LITE;
	} else {
            topGC = GC_DARK;
            bottomGC = GC_DARK;
	}
    }
    if (strcmp(relief, "flat") == 0) {
        topGC = GC_BRDR;
        bottomGC = GC_BRDR;
    }
    if (strcmp(relief, "groove") == 0) {
        topGC = GC_DARK;
        bottomGC = GC_LITE;
    }
    if (strcmp(relief, "ridge") == 0) {
        topGC = GC_LITE;
        bottomGC = GC_DARK;
    }
    if (strcmp(relief, "solid") == 0) {
        topGC = GC_BLAK;
        bottomGC = GC_BLAK;
    }
    if (strcmp(relief, "sunken") == 0) {
        if (topBevel) {
            topGC = GC_DARK;
            bottomGC = GC_DARK;
	} else {
            topGC = GC_LITE;
            bottomGC = GC_LITE;
	}
    }

    x1 = x;
    if (!leftIn) {
        x1 += height;
    }
    x2 = x+width;
    if (!rightIn) {
        x2 -= height;
    }
    x1Delta = (leftIn) ? 1 : -1;
    x2Delta = (rightIn) ? -1 : 1;
    halfway = y + height/2;
    if (!topBevel && (height & 1)) {
        halfway++;
    }
    bottom = y + height;

    for ( ; y < bottom; y++) {
        if (x1 < x2) {
            if (y < halfway) {
	        myGC = topGC;
	    } else {
                myGC = bottomGC;
	    }
	    switch (myGC) {
            case GC_LITE:
                    obj = BuildVertexInfo(interp, x1, y, z, x2-x1, 1, depth, shadow_colors.light_red,
                        shadow_colors.light_green, shadow_colors.light_blue, shadow_colors.light_alpha, side);
        
	        break;
            case GC_DARK:
                    obj = BuildVertexInfo(interp, x1, y, z, x2-x1, 1, depth, shadow_colors.dark_red,
                        shadow_colors.dark_green, shadow_colors.dark_blue, shadow_colors.dark_alpha, side);
		break;
            case GC_BRDR:
            case GC_BLAK:
fprintf(stderr, "GC_BRDR and GC_BLAK not yet implemented!!\n");
                exit(1);
		break;
            default:
fprintf(stderr, "unexpected default in HotizontalBevel!!\n");
                exit(1);
		break;
	    }
            cmd_obj = Tcl_NewStringObj("::gles2::builtin::fillrectangle", -1);
	    cmd_objv[0] = cmd_obj;
	    if (Tcl_ListObjReplace(interp, obj, 0, 0, 1, cmd_objv) != TCL_OK) {
fprintf(stderr, "HorzontalBevel: cannot insert command in front of vertex info\n");
                 exit(1);
	    }
            if (Tcl_EvalObjEx(interp, obj, 0) != TCL_OK) {
fprintf(stderr, "HorzontalBevel: error in executing fillrectangle command:%s\n", Tcl_GetStringResult(interp));
                exit(1);
	     }
         }
         x1 += x1Delta;
         x2 += x2Delta;
    }
}

 
/*
 * ------------------------------------------------------------------------
 *  Gles2_BiInit()
 *
 *  Creates a namespace full of built-in methods/procs for [incr Tcl]
 *  classes.  This includes things like the "isa" method and "info"
 *  for querying class info.  Usually invoked by Itcl_Init() when
 *  [incr Tcl] is first installed into an interpreter.
 *
 *  Returns TCL_OK/TCL_ERROR to indicate success/failure.
 * ------------------------------------------------------------------------
 */
int
Gles2_BiInit(
    Tcl_Interp *interp      /* current interpreter */
................................................................................
fprintf(stderr, "bad value for blue!%s!\n", Tcl_GetString(objv[3]));
        return TCL_ERROR;
    }
    if (Tcl_GetDoubleFromObj(interp, objv[4], &alpha) != TCL_OK) {
fprintf(stderr, "bad value for alpha!%s!\n", Tcl_GetString(objv[4]));
        return TCL_ERROR;
    }
// GL_CHECK(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
 GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
// GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR));
// GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_DST_ALPHA));
// GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_DST_COLOR));
 GL_CHECK(glEnable(GL_BLEND));
// GL_CHECK(glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR));
//( GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_DST_COLOR));
// GL_CHECK(glBlendFunc(GL_ONE, GL_ZERO));
// GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); // OK?
    setupVBOs0();
    gl_red = (GLfloat)(red/255.0);
    gl_green = (GLfloat)(green/255.0);
    gl_blue = (GLfloat)(blue/255.0);
    gl_alpha = (GLfloat)(alpha/255.0);
    GL_CHECK(glClearColor(gl_red, gl_green,gl_blue, gl_alpha));
    GL_CHECK(glClear(GL_COLOR_BUFFER_BIT));
................................................................................

//fprintf(stderr, "FILLRECT!%f!%f!%f %f!%f!%f\n", rectangle_vertices[0].Position[0], rectangle_vertices[0].Position[1], rectangle_vertices[0].Position[2], rectangle_vertices[1].Position[0], rectangle_vertices[1].Position[1], rectangle_vertices[1].Position[2]);

    GL_CHECK(glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0));
    GL_CHECK(glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
        sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)));

//fprintf(stderr, "fillRectangle before %f %f %f\n", xangle, yangle, zangle);
    handleMatrices(xangle, yangle, zangle);

    GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(rectangle_vertices), &rectangle_vertices, GL_STATIC_DRAW));
    GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(rectangle_indices), &rectangle_indices, GL_STATIC_DRAW));
    GL_CHECK(glDrawElements(GL_TRIANGLES, sizeof(rectangle_indices)/sizeof(rectangle_indices[0]), GL_UNSIGNED_BYTE, 0));

    return result;
................................................................................
    GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(rectangle_vertices), &rectangle_vertices, GL_STATIC_DRAW));
    GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(draw_rectangle_indices), &draw_rectangle_indices, GL_STATIC_DRAW));
    GL_CHECK(glDrawElements(GL_LINES, sizeof(draw_rectangle_indices)/sizeof(draw_rectangle_indices[0]), GL_UNSIGNED_BYTE, 0));

    return result;
}

/*
 * ------------------------------------------------------------------------
 *  Gles2_BiDrawRectangleBorderCmd()
 *
 *  Invoked to handle the "drawrectangleborder" command
 *  Handles the
 *  following syntax:
 *
 *    drawrectangleborder [list x y z width height depth] borderWidth relief
 *        [list darkColor lightColor]
 *
 * ------------------------------------------------------------------------
 */
int Gles2_BiDrawRectangleBorderCmd(
    ClientData dummy,        /* not used */
    Tcl_Interp *interp,      /* current interpreter */
    int objc,                /* number of arguments */
    Tcl_Obj *const objv[])   /* argument objects */
{
    int result = TCL_OK;
    int box_objc;
    Tcl_Obj **boxObjv;
    int shadow_objc;
    Tcl_Obj **shadowObjv;
    int dark_objc;
    Tcl_Obj **darkObjv;
    int light_objc;
    Tcl_Obj **lightObjv;
    positionBox position_box;
    int borderWidth;
    char *relief;
    shadowColors shadow_colors;

    Gles2ShowArgs(1, "Gles2_BiDrawRectangleBorderCmd", objc, objv);
    if (objc != 5) {
        Tcl_WrongNumArgs(interp, 1, objv, "box borderWidth relief shadowColors");
        return TCL_ERROR;
    }
    if (Tcl_ListObjGetElements(interp, objv[1], &box_objc, &boxObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd1: bad input format: %s\n", Tcl_GetString(objv[1]));
        return TCL_ERROR;
    }
    if (box_objc != 6) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd2: bad input format: %s %d\n", Tcl_GetString(objv[1]), box_objc);
        return TCL_ERROR;
    }

    /* x */
    if (Tcl_GetIntFromObj(interp, boxObjv[0], &position_box.x) != TCL_OK) {
fprintf(stderr, "bad value for x!%s!\n", Tcl_GetString(boxObjv[0]));
        return TCL_ERROR;
    }
    /* y */
    if (Tcl_GetIntFromObj(interp, boxObjv[1], &position_box.y) != TCL_OK) {
fprintf(stderr, "bad value for y!%s!\n", Tcl_GetString(boxObjv[1]));
        return TCL_ERROR;
    }
    /* z */
    if (Tcl_GetIntFromObj(interp, boxObjv[2], &position_box.z) != TCL_OK) {
fprintf(stderr, "bad value for z!%s!\n", Tcl_GetString(boxObjv[2]));
        return TCL_ERROR;
    }
    /* width */
    if (Tcl_GetIntFromObj(interp, boxObjv[3], &position_box.width) != TCL_OK) {
fprintf(stderr, "bad value for width!%s!\n", Tcl_GetString(boxObjv[3]));
        return TCL_ERROR;
    }
    /* height */
    if (Tcl_GetIntFromObj(interp, boxObjv[4], &position_box.height) != TCL_OK) {
fprintf(stderr, "bad value for height!%s!\n", Tcl_GetString(boxObjv[4]));
        return TCL_ERROR;
    }
    /* depth */
    if (Tcl_GetIntFromObj(interp, boxObjv[5], &position_box.depth) != TCL_OK) {
fprintf(stderr, "bad value for depth!%s!\n", Tcl_GetString(boxObjv[5]));
        return TCL_ERROR;
    }
//fprintf(stderr, "POS!%d!%d!%d %d!%d!%d!\n", position_box.x, position_box.y, position_box.z, position_box.width, position_box.height, position_box.depth);
    /* borderWidth */
    if (Tcl_GetIntFromObj(interp, objv[2], &borderWidth) != TCL_OK) {
fprintf(stderr, "bad value for borderWidth!%s!\n", Tcl_GetString(objv[2]));
        return TCL_ERROR;
    }
    relief = Tcl_GetString(objv[3]);

    if (Tcl_ListObjGetElements(interp, objv[4], &shadow_objc, &shadowObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd3: bad input format: %s\n", Tcl_GetString(objv[4]));
        return TCL_ERROR;
    }
    if (shadow_objc != 2) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd4: bad input format: %s %d\n", Tcl_GetString(objv[4]), shadow_objc);
        return TCL_ERROR;
    }
    if (Tcl_ListObjGetElements(interp, shadowObjv[0], &dark_objc, &darkObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd5: bad input format: %s\n", Tcl_GetString(shadowObjv[0]));
        return TCL_ERROR;
    }
    if (dark_objc != 4) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd6: bad input format: %s %d\n", Tcl_GetString(shadowObjv[0]), dark_objc);
        return TCL_ERROR;
    }
    /* dark_red */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[0], &shadow_colors.dark_red) != TCL_OK) {
fprintf(stderr, "bad value for dark_red!%s!\n", Tcl_GetString(darkObjv[0]));
        return TCL_ERROR;
    }
    /* dark_green */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[1], &shadow_colors.dark_green) != TCL_OK) {
fprintf(stderr, "bad value for dark_green!%s!\n", Tcl_GetString(darkObjv[1]));
        return TCL_ERROR;
    }
    /* dark_blue */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[2], &shadow_colors.dark_blue) != TCL_OK) {
fprintf(stderr, "bad value for dark_blue!%s!\n", Tcl_GetString(darkObjv[2]));
        return TCL_ERROR;
    }
    /* dark_alpha */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[3], &shadow_colors.dark_alpha) != TCL_OK) {
fprintf(stderr, "bad value for dark_alpha!%s!\n", Tcl_GetString(darkObjv[3]));
        return TCL_ERROR;
    }

    if (Tcl_ListObjGetElements(interp, shadowObjv[1], &light_objc, &lightObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd7: bad input format: %s\n", Tcl_GetString(shadowObjv[1]));
        return TCL_ERROR;
    }
    if (light_objc != 4) {
fprintf(stderr, "Gles2_BiDrawRectangleBorderCmd8: bad input format: %s %d\n", Tcl_GetString(shadowObjv[1]), light_objc);
        return TCL_ERROR;
    }
    /* light_red */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[0], &shadow_colors.light_red) != TCL_OK) {
fprintf(stderr, "bad value for light_red!%s!\n", Tcl_GetString(lightObjv[0]));
        return TCL_ERROR;
    }
    /* light_green */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[1], &shadow_colors.light_green) != TCL_OK) {
fprintf(stderr, "bad value for light_green!%s!\n", Tcl_GetString(lightObjv[1]));
        return TCL_ERROR;
    }
    /* light_blue */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[2], &shadow_colors.light_blue) != TCL_OK) {
fprintf(stderr, "bad value for light_blue!%s!\n", Tcl_GetString(lightObjv[2]));
        return TCL_ERROR;
    }
    /* light_alpha */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[3], &shadow_colors.light_alpha) != TCL_OK) {
fprintf(stderr, "bad value for light_alpha!%s!\n", Tcl_GetString(lightObjv[3]));
        return TCL_ERROR;
    }
    if (position_box.width < 2*borderWidth) {
        borderWidth = position_box.width/2;
    }
    if (position_box.height < 2*borderWidth) {
        borderWidth = position_box.height/2;
    }
    VerticalBevel(interp, position_box.x, position_box.y, position_box.z, borderWidth, position_box.height, position_box.depth, 1, relief, shadow_colors, FRONT_SIDE);
    if (position_box.depth > 0) {
        VerticalBevel(interp, position_box.x, position_box.y, position_box.z, borderWidth, position_box.height, position_box.depth, 1, relief, shadow_colors, RIGHT_SIDE);
        VerticalBevel(interp, position_box.x, position_box.y, position_box.z, borderWidth, position_box.height, position_box.depth, 1, relief, shadow_colors, LEFT_SIDE);
    }
    VerticalBevel(interp, position_box.x+position_box.width-borderWidth, position_box.y, position_box.z, borderWidth, position_box.height, position_box.depth, 0, relief, shadow_colors, FRONT_SIDE);
    if (position_box.depth > 0) {
        VerticalBevel(interp, position_box.x+position_box.width-borderWidth, position_box.y, position_box.z, borderWidth, position_box.height, position_box.depth, 0, relief, shadow_colors, RIGHT_SIDE);
        VerticalBevel(interp, position_box.x+position_box.width-borderWidth, position_box.y, position_box.z, borderWidth, position_box.height, position_box.depth, 0, relief, shadow_colors, LEFT_SIDE);
    }
    HorizontalBevel(interp, position_box.x, position_box.y+position_box.height-borderWidth, position_box.z, position_box.width, borderWidth, position_box.depth, 1, 1, 1, relief, shadow_colors, FRONT_SIDE);
    if (position_box.depth > 0) {
        HorizontalBevel(interp, position_box.x, position_box.y+position_box.height-borderWidth, position_box.z, position_box.width, borderWidth, position_box.depth, 1, 1, 1, relief, shadow_colors, TOP_SIDE);
        HorizontalBevel(interp, position_box.x, position_box.y+position_box.height-borderWidth, position_box.z, position_box.width, borderWidth, position_box.depth, 1, 1, 1, relief, shadow_colors, BOTTOM_SIDE);
        HorizontalBevel(interp, position_box.x, position_box.y+position_box.height-borderWidth, position_box.z, position_box.width, borderWidth, position_box.depth, 1, 1, 1, relief, shadow_colors, BACK_SIDE);
    }
    HorizontalBevel(interp, position_box.x, position_box.y, position_box.z, position_box.width, borderWidth, position_box.depth, 0, 0, 0, relief, shadow_colors, FRONT_SIDE);
    if (position_box.depth > 0) {
        HorizontalBevel(interp, position_box.x, position_box.y, position_box.z, position_box.width, borderWidth, position_box.depth, 0, 0, 0, relief, shadow_colors, TOP_SIDE);
        HorizontalBevel(interp, position_box.x, position_box.y, position_box.z, position_box.width, borderWidth, position_box.depth, 0, 0, 0, relief, shadow_colors, BOTTOM_SIDE);
        HorizontalBevel(interp, position_box.x, position_box.y, position_box.z, position_box.width, borderWidth, position_box.depth, 0, 0, 0, relief, shadow_colors, BACK_SIDE);
    }

    return result;
}

/*
 * ------------------------------------------------------------------------
 *  Gles2_BiDrawDiamondBorderCmd()
 *
 *  Invoked to handle the "drawdiamondborder" command
 *  Handles the
 *  following syntax:
 *
 *    drawdamondborder [list x y width height] borderWidth relief diameter
 *        [list darkColor lightColor]
 *
 * ------------------------------------------------------------------------
 */
int Gles2_BiDrawDiamondBorderCmd(
    ClientData dummy,        /* not used */
    Tcl_Interp *interp,      /* current interpreter */
    int objc,                /* number of arguments */
    Tcl_Obj *const objv[])   /* argument objects */
{
    int result = TCL_OK;
    int box_objc;
    Tcl_Obj **boxObjv;
    int shadow_objc;
    Tcl_Obj **shadowObjv;
    int dark_objc;
    Tcl_Obj **darkObjv;
    int light_objc;
    Tcl_Obj **lightObjv;
    positionBox position_box;
    int borderWidth;
    int diameter;
    GLfloat radius;
    char *relief;
    shadowColors shadow_colors;

    Gles2ShowArgs(1, "Gles2_BiDrawDiamondBorderCmd", objc, objv);
    if (objc != 6) {
        Tcl_WrongNumArgs(interp, 1, objv, "box borderWidth relief diameter shadowColors");
        return TCL_ERROR;
    }
    if (Tcl_ListObjGetElements(interp, objv[1], &box_objc, &boxObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd1: bad input format: %s\n", Tcl_GetString(objv[1]));
        return TCL_ERROR;
    }
    if (box_objc != 4) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd2: bad input format: %s %d\n", Tcl_GetString(objv[1]), box_objc);
        return TCL_ERROR;
    }

    /* x */
    if (Tcl_GetIntFromObj(interp, boxObjv[0], &position_box.x) != TCL_OK) {
fprintf(stderr, "bad value for x!%s!\n", Tcl_GetString(boxObjv[0]));
        return TCL_ERROR;
    }
    /* y */
    if (Tcl_GetIntFromObj(interp, boxObjv[1], &position_box.y) != TCL_OK) {
fprintf(stderr, "bad value for y!%s!\n", Tcl_GetString(boxObjv[1]));
        return TCL_ERROR;
    }
    /* width */
    if (Tcl_GetIntFromObj(interp, boxObjv[2], &position_box.width) != TCL_OK) {
fprintf(stderr, "bad value for width!%s!\n", Tcl_GetString(boxObjv[2]));
        return TCL_ERROR;
    }
    /* height */
    if (Tcl_GetIntFromObj(interp, boxObjv[3], &position_box.height) != TCL_OK) {
fprintf(stderr, "bad value for height!%s!\n", Tcl_GetString(boxObjv[3]));
        return TCL_ERROR;
    }
    /* borderWidth */
    if (Tcl_GetIntFromObj(interp, objv[2], &borderWidth) != TCL_OK) {
fprintf(stderr, "bad value for borderWidth!%s!\n", Tcl_GetString(objv[2]));
        return TCL_ERROR;
    }
    relief = Tcl_GetString(objv[3]);
    /* diameter */
    if (Tcl_GetIntFromObj(interp, objv[4], &diameter) != TCL_OK) {
fprintf(stderr, "bad value for diameter!%s!\n", Tcl_GetString(objv[4]));
        return TCL_ERROR;
    }

    if (Tcl_ListObjGetElements(interp, objv[5], &shadow_objc, &shadowObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd3: bad input format: %s\n", Tcl_GetString(objv[5]));
        return TCL_ERROR;
    }
    if (shadow_objc != 2) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd4: bad input format: %s %d\n", Tcl_GetString(objv[4]), shadow_objc);
        return TCL_ERROR;
    }
    if (Tcl_ListObjGetElements(interp, shadowObjv[0], &dark_objc, &darkObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd5: bad input format: %s\n", Tcl_GetString(shadowObjv[0]));
        return TCL_ERROR;
    }
    if (dark_objc != 4) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd6: bad input format: %s %d\n", Tcl_GetString(shadowObjv[0]), dark_objc);
        return TCL_ERROR;
    }
    /* dark_red */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[0], &shadow_colors.dark_red) != TCL_OK) {
fprintf(stderr, "bad value for dark_red!%s!\n", Tcl_GetString(darkObjv[0]));
        return TCL_ERROR;
    }
    /* dark_green */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[1], &shadow_colors.dark_green) != TCL_OK) {
fprintf(stderr, "bad value for dark_green!%s!\n", Tcl_GetString(darkObjv[1]));
        return TCL_ERROR;
    }
    /* dark_blue */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[2], &shadow_colors.dark_blue) != TCL_OK) {
fprintf(stderr, "bad value for dark_blue!%s!\n", Tcl_GetString(darkObjv[2]));
        return TCL_ERROR;
    }
    /* dark_alpha */
    if (Tcl_GetDoubleFromObj(interp, darkObjv[3], &shadow_colors.dark_alpha) != TCL_OK) {
fprintf(stderr, "bad value for dark_alpha!%s!\n", Tcl_GetString(darkObjv[3]));
        return TCL_ERROR;
    }

    if (Tcl_ListObjGetElements(interp, shadowObjv[1], &light_objc, &lightObjv) != TCL_OK) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd7: bad input format: %s\n", Tcl_GetString(shadowObjv[1]));
        return TCL_ERROR;
    }
    if (light_objc != 4) {
fprintf(stderr, "Gles2_BiDrawDiamondBorderCmd8: bad input format: %s %d\n", Tcl_GetString(shadowObjv[1]), light_objc);
        return TCL_ERROR;
    }
    /* light_red */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[0], &shadow_colors.light_red) != TCL_OK) {
fprintf(stderr, "bad value for light_red!%s!\n", Tcl_GetString(lightObjv[0]));
        return TCL_ERROR;
    }
    /* light_green */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[1], &shadow_colors.light_green) != TCL_OK) {
fprintf(stderr, "bad value for light_green!%s!\n", Tcl_GetString(lightObjv[1]));
        return TCL_ERROR;
    }
    /* light_blue */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[2], &shadow_colors.light_blue) != TCL_OK) {
fprintf(stderr, "bad value for light_blue!%s!\n", Tcl_GetString(lightObjv[2]));
        return TCL_ERROR;
    }
    /* light_alpha */
    if (Tcl_GetDoubleFromObj(interp, lightObjv[3], &shadow_colors.light_alpha) != TCL_OK) {
fprintf(stderr, "bad value for light_alpha!%s!\n", Tcl_GetString(lightObjv[3]));
        return TCL_ERROR;
    }

    radius = diameter / 2.0;
    if (position_box.width < 2*borderWidth) {
        borderWidth = position_box.width/2;
    }
    if (position_box.height < 2*borderWidth) {
        borderWidth = position_box.height/2;
    }
    LeftTopBevel(interp, position_box.x, position_box.y, diameter, diameter, 1, relief, shadow_colors);
    LeftTopBevel(interp, position_box.x+radius, position_box.y-radius, diameter, diameter, 0, relief, shadow_colors);
    LeftBottomBevel(interp, position_box.x, position_box.y, diameter, diameter, 0, relief, shadow_colors);
    LeftBottomBevel(interp, position_box.x+radius, position_box.y+radius, diameter, diameter, 1, relief, shadow_colors);
    return result;
}

/*
 * ------------------------------------------------------------------------
 *  Gles2_BiFillTextureRectangleCmd()
 *
 *  Invoked to handle the "filltexturerectangle" command
 *  Handles the
 *  following syntax:







<
<







 







<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




|
<
|
|







 







<
|
<
<
<
|
<
<
<
<







 







<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







23
24
25
26
27
28
29


30
31
32
33
34
35
36
..
99
100
101
102
103
104
105












106
107
108
109
110
111
112
...
377
378
379
380
381
382
383






384










































































































































































































































































































































































































































































































































385
386
387
388
389

390
391
392
393
394
395
396
397
398
...
476
477
478
479
480
481
482

483



484




485
486
487
488
489
490
491
...
888
889
890
891
892
893
894

895
896
897
898
899
900
901
...
963
964
965
966
967
968
969























































































































































































































































































































































970
971
972
973
974
975
976
static Tcl_ObjCmdProc Gles2_BiClearBufferCmd;
static Tcl_ObjCmdProc Gles2_BiDrawLineCmd;
static Tcl_ObjCmdProc Gles2_BiFillTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiFillTextureTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawTextureTriangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawRectangleCmd;


static Tcl_ObjCmdProc Gles2_BiFillRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiFillTextureRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiDrawTextureRectangleCmd;
static Tcl_ObjCmdProc Gles2_BiSetupRenderBufferCmd;
static Tcl_ObjCmdProc Gles2_BiSetupFrameBufferCmd;
static Tcl_ObjCmdProc Gles2_BiCompileShadersCmd;
static Tcl_ObjCmdProc Gles2_BiGetFontInfoCmd;
................................................................................
	0
    },
    { "drawrectangle",
        "vertex1 vertex2 vertex3 vertex4",
        "@gles2-builtin-drawrectangle",
        Gles2_BiDrawRectangleCmd,
	0












    },
    { "filltexturerectangle",
        "vertex1 vertex2 vertex3 vertex4",
        "@gles2-builtin-filltexturerectangle",
        Gles2_BiFillTextureRectangleCmd,
	0
    },
................................................................................
//showMatrix("per1", g_Perspective);
    multiply_matrix(g_Perspective, g_ModelView, g_MVP);
//showMatrix("mul3", g_MVP);

    GL_CHECK(glUniformMatrix4fv(_projectionSlot, 1, GL_FALSE, g_MVP));
}







 










































































































































































































































































































































































































































































































































/*
 * ------------------------------------------------------------------------
 *  Gles2_BiInit()
 *
 *  Creates a namespace full of built-in methods/procs for gles2

 *  Usually invoked by Gles2_Init() when
 *  gles2 is first installed into an interpreter.
 *
 *  Returns TCL_OK/TCL_ERROR to indicate success/failure.
 * ------------------------------------------------------------------------
 */
int
Gles2_BiInit(
    Tcl_Interp *interp      /* current interpreter */
................................................................................
fprintf(stderr, "bad value for blue!%s!\n", Tcl_GetString(objv[3]));
        return TCL_ERROR;
    }
    if (Tcl_GetDoubleFromObj(interp, objv[4], &alpha) != TCL_OK) {
fprintf(stderr, "bad value for alpha!%s!\n", Tcl_GetString(objv[4]));
        return TCL_ERROR;
    }

    GL_CHECK(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));



    GL_CHECK(glEnable(GL_BLEND));




    setupVBOs0();
    gl_red = (GLfloat)(red/255.0);
    gl_green = (GLfloat)(green/255.0);
    gl_blue = (GLfloat)(blue/255.0);
    gl_alpha = (GLfloat)(alpha/255.0);
    GL_CHECK(glClearColor(gl_red, gl_green,gl_blue, gl_alpha));
    GL_CHECK(glClear(GL_COLOR_BUFFER_BIT));
................................................................................

//fprintf(stderr, "FILLRECT!%f!%f!%f %f!%f!%f\n", rectangle_vertices[0].Position[0], rectangle_vertices[0].Position[1], rectangle_vertices[0].Position[2], rectangle_vertices[1].Position[0], rectangle_vertices[1].Position[1], rectangle_vertices[1].Position[2]);

    GL_CHECK(glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0));
    GL_CHECK(glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, 
        sizeof(Vertex), (GLvoid*) (sizeof(float) * 3)));


    handleMatrices(xangle, yangle, zangle);

    GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(rectangle_vertices), &rectangle_vertices, GL_STATIC_DRAW));
    GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(rectangle_indices), &rectangle_indices, GL_STATIC_DRAW));
    GL_CHECK(glDrawElements(GL_TRIANGLES, sizeof(rectangle_indices)/sizeof(rectangle_indices[0]), GL_UNSIGNED_BYTE, 0));

    return result;
................................................................................
    GL_CHECK(glBufferData(GL_ARRAY_BUFFER, sizeof(rectangle_vertices), &rectangle_vertices, GL_STATIC_DRAW));
    GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(draw_rectangle_indices), &draw_rectangle_indices, GL_STATIC_DRAW));
    GL_CHECK(glDrawElements(GL_LINES, sizeof(draw_rectangle_indices)/sizeof(draw_rectangle_indices[0]), GL_UNSIGNED_BYTE, 0));

    return result;
}
























































































































































































































































































































































/*
 * ------------------------------------------------------------------------
 *  Gles2_BiFillTextureRectangleCmd()
 *
 *  Invoked to handle the "filltexturerectangle" command
 *  Handles the
 *  following syntax:

Changes to generic/gles2Helpers.c.

540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
...
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
}

/*
 *
 * ------------------------------------------------------------------------
 *  GetElementPositions()
 *
 *  convert a parcel coordinates to graphics context positions
 * ------------------------------------------------------------------------
 */

Tcl_Obj *
GetElementPositions(
    Tcl_Interp *interp,      /* current interpreter */
    Tcl_Obj *obj)            /* value to convert */
................................................................................
    int x;
    int y;
    int width;
    int height;
    GLfloat f_x;
    GLfloat f_y;
    GLfloat f_z;
//    GLfloat f_width;
//    GLfloat f_height;
    GLfloat radius;
    GLfloat w_radius;
    GLfloat h_radius;

    radius = diameter / 2.0;
    w_radius = Pixel2Coord(interp, radius, 1);
    h_radius = Pixel2Coord(interp, radius, 0);







|







 







<
<







540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
...
699
700
701
702
703
704
705


706
707
708
709
710
711
712
}

/*
 *
 * ------------------------------------------------------------------------
 *  GetElementPositions()
 *
 *  convert parcel coordinates to graphics context positions
 * ------------------------------------------------------------------------
 */

Tcl_Obj *
GetElementPositions(
    Tcl_Interp *interp,      /* current interpreter */
    Tcl_Obj *obj)            /* value to convert */
................................................................................
    int x;
    int y;
    int width;
    int height;
    GLfloat f_x;
    GLfloat f_y;
    GLfloat f_z;


    GLfloat radius;
    GLfloat w_radius;
    GLfloat h_radius;

    radius = diameter / 2.0;
    w_radius = Pixel2Coord(interp, radius, 1);
    h_radius = Pixel2Coord(interp, radius, 0);