Changeset 321 for trunk/thune/gl

Show
Ignore:
Timestamp:
12/22/06 19:52:46 (2 years ago)
Author:
krobillard
Message:

Thune GL - Added display.snapshot & save.png. Some code cleanup.

Location:
trunk/thune/gl
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/gl/gx.c

    r312 r321  
    629629    { 
    630630        ur_initType(tos, UT_NONE ); 
     631    } 
     632} 
     633 
     634 
     635// ( -- raster) 
     636UR_CALL( uc_display_snap ) 
     637{ 
     638    UBinary* bin; 
     639    GLint vp[ 4 ];  // x, y, w, h 
     640 
     641    glGetIntegerv( GL_VIEWPORT, vp ); 
     642 
     643    ur_makeRaster( ur_s_next(tos), UR_RAST_RGB, vp[2], vp[3], &bin ); 
     644    UR_S_GROW; 
     645 
     646    if( bin->ptr.b ) 
     647    { 
     648        // Grab front buffer or we are likely to grab a blank screen 
     649        // (since key input is done after glClear). 
     650        glReadBuffer( GL_FRONT ); 
     651        glReadPixels( vp[0], vp[1], vp[2], vp[3], GL_RGB, GL_UNSIGNED_BYTE, 
     652                      ur_rastElem(bin) ); 
    631653    } 
    632654} 
     
    12881310 
    12891311 
    1290 #if 0 
    1291 #if 0 
    1292 /* 
    1293    Returns number of valid values. 
    1294 */ 
    1295 static int fetchNumbers( double* dim, UCell* val, int count ) 
    1296 { 
    1297     UCell* end = val + count; 
    1298     while( val != end ) 
    1299     { 
    1300         if( val->type == OT_INTEGER ) 
    1301             *dim = (double) orInt(val); 
    1302         else if( val->type == OT_DECIMAL ) 
    1303             *dim = orDecimal(val); 
    1304         else 
    1305         { 
    1306             --count; 
    1307             *dim = 0; 
    1308         } 
    1309  
    1310         ++dim; 
    1311         ++val; 
    1312     } 
    1313     return count; 
    1314 } 
    1315 #endif 
    1316  
    1317  
    1318 #define toDecimal(idx,dim) \ 
    1319     if( val->type == OT_DECIMAL ) \ 
    1320         num[idx] = orDecimal(val) * dim; \ 
    1321     else if( val->type == OT_INTEGER ) \ 
    1322         num[idx] = (double) orInt(val); \ 
    1323     else return 0; 
    1324  
    1325 /* 
    1326    Convert decimal! values to view pixels. 
    1327 */ 
    1328 static int loadDimensions( double* num, UCell* val ) 
    1329 { 
    1330     toDecimal( 0, gEnv.view_wd ) 
    1331     ++val; 
    1332     toDecimal( 1, gEnv.view_hd ) 
    1333     ++val; 
    1334     toDecimal( 2, gEnv.view_wd ) 
    1335     ++val; 
    1336     toDecimal( 3, gEnv.view_hd ) 
    1337     return 1; 
    1338 } 
    1339  
    1340  
    1341 /* 
    1342   widget [object!] 
    1343   size   [none! pair!] 
    1344   center [none! matrix! vec3!] 
    1345 */ 
    1346 UR_CALL( orthoViewNative ) 
    1347 { 
    1348     OBlock* vblk; 
    1349     UCell* val; 
    1350     double dim[4]; 
    1351  
    1352     vblk = orBlockPtr( a1->ctx.vblkN ); 
    1353  
    1354     if( vblk->used >= WV_COUNT ) 
    1355     { 
    1356         val = vblk->values + WV_X; 
    1357         if( loadDimensions( dim, val ) ) 
    1358         { 
    1359             glViewport( (GLint) dim[0], 
    1360                         (GLint) dim[1], 
    1361                         (GLsizei) dim[2],  
    1362                         (GLsizei) dim[3] ); 
    1363  
    1364             //printf("KR Dim %g %g %g %g\n", dim[0], dim[1], dim[2], dim[3]); 
    1365  
    1366             val = a1 + 1; 
    1367             if( val->type == OT_PAIR ) 
    1368             { 
    1369                 dim[2] = (double) (val->pair[0] / 2) * gEnv.view_aspect; 
    1370                 dim[3] = (double) (val->pair[1] / 2); 
    1371             } 
    1372             else 
    1373             { 
    1374                 dim[2] *= 0.5; 
    1375                 dim[3] *= 0.5; 
    1376             } 
    1377  
    1378             glMatrixMode( GL_PROJECTION ); 
    1379             glLoadIdentity(); 
    1380             //       left, right, bottom, top, near, far 
    1381             glOrtho( -dim[2], dim[2], -dim[3], dim[3], -100.0, 100.0 ); 
    1382             glMatrixMode( GL_MODELVIEW ); 
    1383         } 
    1384     } 
    1385  
    1386     val = a1 + 2; 
    1387     if( val->type == OT_MATRIX ) 
    1388     { 
    1389         OString* arr; 
    1390         float eye[16]; 
    1391  
    1392         arr = orSTRING(val); 
    1393         orMatrixInverse( eye, arr->floats ); 
    1394         glLoadMatrixf( eye ); 
    1395     } 
    1396     else if( val->type == OT_VEC3 ) 
    1397     { 
    1398         glLoadIdentity(); 
    1399         glTranslatef( -val->vec3.x, -val->vec3.y, -val->vec3.z ); 
    1400     } 
    1401     else 
    1402     { 
    1403         glLoadIdentity(); 
    1404     } 
    1405 } 
    1406  
    1407  
    1408 UR_CALL( viewportNative ) 
    1409 { 
    1410     OBlock* vblk; 
    1411     UCell* val; 
    1412     double dim[4]; 
    1413  
    1414     vblk = orBlockPtr( a1->ctx.vblkN ); 
    1415     if( vblk->used >= WV_COUNT ) 
    1416     { 
    1417         val = vblk->values + WV_X; 
    1418         if( loadDimensions( dim, val ) ) 
    1419         { 
    1420             glViewport( (GLint) dim[0], 
    1421                         (GLint) dim[1], 
    1422                         (GLsizei) dim[2],  
    1423                         (GLsizei) dim[3] ); 
    1424  
    1425             glMatrixMode( GL_PROJECTION ); 
    1426             glLoadIdentity(); 
    1427             //       fovy, aspect, zNear, zFar 
    1428             gluPerspective( 65.0, dim[2] / dim[3], 0.5, 1000.0 ); 
    1429             glMatrixMode( GL_MODELVIEW ); 
    1430         } 
    1431     } 
    1432  
    1433     val = a1 + 1; 
    1434     if( val->type == OT_MATRIX ) 
    1435     { 
    1436         OString* arr; 
    1437         float eye[16]; 
    1438  
    1439         arr = orSTRING(val); 
    1440         orMatrixInverse( eye, arr->floats ); 
    1441         glLoadMatrixf( eye ); 
    1442     } 
    1443     else 
    1444     { 
    1445         glLoadIdentity(); 
    1446     } 
    1447 } 
    1448  
    1449  
    1450 UR_CALL( renderStateNative ) 
    1451 { 
    1452     if( a1->type == OT_WORD ) 
    1453     { 
    1454         if( orAtom(a1) == gEnv.atom_model ) 
    1455         { 
    1456             gxStateModel(); 
    1457         } 
    1458         else if( orAtom(a1) == gEnv.atom_solid ) 
    1459         { 
    1460             gxStateSolid(); 
    1461         } 
    1462     } 
    1463     else if( a1->type == OT_RESOURCE ) 
    1464     { 
    1465         if( a1->RESTYPE == RES_TYPE_FONT ) 
    1466         { 
    1467             FontResource* res = gxFont( a1->index ); 
    1468             if( res ) 
    1469             { 
    1470                 gxStateText(); 
    1471                 glBindTexture( GL_TEXTURE_2D, res->glTexId ); 
    1472  
    1473                 gEnv.state.fontKey = res->res.resKey; 
    1474             } 
    1475         } 
    1476     } 
    1477 } 
    1478  
    1479  
    1480 UR_CALL( renderTextNative ) 
    1481 { 
    1482     FontResource* fnt; 
    1483     UCell* a2 = a1 + 1; 
    1484  
    1485     fnt = gxFont( gEnv.state.fontKey ); 
    1486     if( ! fnt ) 
    1487         return; 
    1488  
    1489     gxSetPen( 0.0f, 0.0f ); 
    1490     glPushMatrix(); 
    1491  
    1492     if( a1->type == OT_PAIR ) 
    1493     { 
    1494         glTranslatef( (GLfloat) a1->pair[0], (GLfloat) a1->pair[1], 0.0f ); 
    1495     } 
    1496     else if( a1->type == OT_VEC3 ) 
    1497     { 
    1498         glTranslatef( a1->vec3.x, a1->vec3.y, a1->vec3.z ); 
    1499     } 
    1500  
    1501     gxDrawTextValue( fnt, a2 ); 
    1502  
    1503     glPopMatrix(); 
    1504 } 
    1505  
    1506  
    1507 UR_CALL( pushNative ) 
    1508 { 
    1509     (void) a1; 
    1510     glPushMatrix(); 
    1511 } 
    1512  
    1513  
    1514 UR_CALL( popNative ) 
    1515 { 
    1516     (void) a1; 
    1517     glPopMatrix(); 
    1518 } 
    1519  
    1520  
    1521 UR_CALL( translateNative ) 
    1522 { 
    1523     GLdouble n[3]; 
    1524     getVector( 3, a1, n ); 
    1525     glTranslated( n[0], n[1], n[2] ); 
    1526     //printf( "KR %g %g %g\n", n[0], n[1], n[2] ); 
    1527 } 
    1528  
    1529  
    1530 #if 0 
    1531 UR_CALL( rotateNative ) 
    1532 { 
    1533     GLdouble n[4]; 
    1534     getVector( 4, a1, n ); 
    1535     glRotated( n[0], n[1], n[2], n[3] ); 
    1536 } 
    1537 #endif 
    1538  
    1539  
    1540 UR_CALL( scaleNative ) 
    1541 { 
    1542     GLdouble n[3]; 
    1543     getVector( 3, a1, n ); 
    1544     glScaled( n[0], n[1], n[2] ); 
    1545 } 
    1546  
    1547  
    1548 UR_CALL( pushMatrixNative ) 
    1549 { 
    1550     OString* arr = orSTRING(a1); 
    1551     glPushMatrix(); 
    1552     glMultMatrixf( arr->floats ); 
    1553     //glLoadMatrixf( arr->floats ); 
    1554 } 
    1555  
    1556  
    1557 UR_CALL( moveNative ) 
    1558 { 
    1559     if( a1->type == OT_MATRIX ) 
    1560     { 
    1561         OString* arr; 
    1562         float* pf; 
    1563         UCell* it; 
    1564         UCell* end; 
    1565  
    1566         arr = orSTRING(a1); 
    1567         pf = arr->floats + 12; 
    1568  
    1569         it  = a1 + 1; 
    1570         end = it + 3; 
    1571  
    1572         while( it != end ) 
    1573         { 
    1574             if( it->type == OT_DECIMAL ) 
    1575                 *pf += (float) orDecimal(it); 
    1576             else if( it->type == OT_INTEGER ) 
    1577                 *pf += (float) orInt(it); 
    1578  
    1579             ++pf; 
    1580             ++it; 
    1581         } 
    1582     } 
    1583 } 
    1584  
    1585  
    1586 UR_CALL( rotateNative ) 
    1587 { 
    1588     double angle; 
    1589     float rmat[16]; 
    1590     UCell* a2 = a1 + 1; 
    1591     UCell* a3 = a1 + 2; 
    1592  
    1593     if( (a1->type == OT_MATRIX) && (a2->type == OT_VEC3) ) 
    1594     { 
    1595         OString* arr = orSTRING(a1); 
    1596  
    1597         if( a3->type == OT_DECIMAL ) 
    1598             angle = orDecimal(a3); 
    1599         else if( a3->type == OT_INTEGER ) 
    1600             angle = (double) orInt(a3); 
    1601         else 
    1602             angle = 0.0; 
    1603  
    1604         if( angle ) 
    1605         { 
    1606             orLoadRotation( rmat, &a2->vec3.x, (float) degToRad(angle) ); 
    1607             orMatrixMult( arr->floats, rmat, arr->floats ); 
    1608         } 
    1609     } 
    1610 } 
    1611 #endif 
    1612  
    1613  
    1614 #if 0 
    1615 UR_CALL( screengrabNative ) 
    1616 { 
    1617     OBinary* bin; 
    1618     GLint vp[ 4 ]; 
    1619     GLint x, y, w, h; 
    1620  
    1621     (void) a1; 
    1622     glGetIntegerv( GL_VIEWPORT, vp ); 
    1623  
    1624     x = vp[0]; 
    1625     y = vp[1]; 
    1626     w = vp[2]; 
    1627     h = vp[3]; 
    1628  
    1629     bin = orMakeImage( UR_IMG_RGB, w, h ); 
    1630     if( bin->byteArray ) 
    1631     { 
    1632         // Grab front buffer or we are likely to grab a blank screen 
    1633         // (since key input is done after glClear). 
    1634         glReadBuffer( GL_FRONT ); 
    1635         glReadPixels( x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, 
    1636                       orImagePixels(bin) ); 
    1637     } 
    1638     //orResultSeries( OT_BINARY, orBinaryN(bin), 0 ); 
    1639     orResultSeries( OT_IMAGE, orBinaryN(bin), 0 ); 
    1640 } 
    1641  
    1642  
    1643 UR_CALL( mouseHandlerNative ) 
    1644 { 
    1645     orBind( orBLOCK(a1), &gEnv.input_ctx ); 
    1646 } 
    1647  
    1648  
    1649 UR_CALL( keyHandlerNative ) 
    1650 { 
    1651     if( validKeyHandlerBlock( a1->index, a1->series.it ) ) 
    1652     { 
    1653         OBlock* blk2 = orCopyBlock( a1->index, a1->series.it, 0 ); 
    1654         mapKeyAtoms( blk2 ); 
    1655         orSetSeries( a1, orBlockN(blk2), 0 ); 
    1656     } 
    1657     else 
    1658     { 
    1659         orError( "Invalid key-handler block" ); 
    1660     } 
    1661 } 
    1662  
    1663  
    1664 static char* _lowercase( const char* cp, int len ) 
    1665 { 
    1666     int c; 
    1667     char* it  = orTmp; 
    1668     char* end = it + len; 
    1669  
    1670     assert( len < OR_TMP_SIZE ); 
    1671  
    1672     while( it != end ) 
    1673     { 
    1674         c = *cp++; 
    1675         if( c >= 'A' && c <= 'Z' ) 
    1676             c -= 'A' - 'a'; 
    1677         *it++ = c; 
    1678     } 
    1679     return orTmp; 
    1680 } 
    1681  
    1682  
    1683 uint32_t gxHashString( UCell* val ) 
    1684 { 
    1685     OString* str = orSTRING( val ); 
    1686     char* cp = orStrChars( str, val ); 
    1687     int len = orSeriesLen( str, val ); 
    1688     return resd_hash( _lowercase(cp, len), len ); 
    1689 } 
    1690  
    1691  
    1692 UR_CALL( hashNative ) 
    1693 { 
    1694     uint32_t key = gxHashString(a1); 
    1695     orResult( OT_INTEGER, key ); 
    1696 } 
    1697  
    1698  
    1699 UR_CALL( resourceNative ) 
    1700 { 
    1701     uint32_t key; 
    1702     Resource* res; 
    1703  
    1704     if( a1->type == OT_INTEGER ) 
    1705         key = orInt(a1); 
    1706     else 
    1707         key = gxHashString(a1); 
    1708  
    1709     res = resd_lookup( &gEnv.resd, key ); 
    1710     if( res ) 
    1711     { 
    1712         orSetTF( a1, OT_PAIR ); 
    1713         a1->pair[0] = key; 
    1714         a1->pair[1] = ((TextureResource*) res)->glTexId; 
    1715     } 
    1716     else 
    1717     { 
    1718         orError( "resource not found for key %u.", key ); 
    1719     } 
    1720 } 
    1721  
    1722  
    1723 #define REF_RG_FREE     a1+1 
    1724  
    1725 UR_CALL( resourceGroupNative ) 
    1726 { 
    1727     uint16_t id; 
    1728  
    1729     if( a1->type == OT_INTEGER ) 
    1730         id = orInt(a1); 
    1731     else if( a1->type == OT_WORD ) 
    1732         id = orAtom(a1); 
    1733  
    1734     if( orRefineSet(REF_RG_FREE) ) 
    1735         resd_freeGroup( &gEnv.resd, id ); 
    1736     else 
    1737         resd_setCurrentGroup( id ); 
    1738 } 
    1739  
    1740  
    1741 // This must go when 'save is added to the core library. 
    1742 UR_CALL( saveNative ) 
    1743 { 
    1744     FILE* fp; 
    1745     OString* str; 
    1746     char* file; 
    1747     OBinary* bin; 
    1748     UCell* a2 = a1 + 1; 
    1749  
    1750     bin = orSTRING( a2 ); 
    1751     if( bin->buf ) 
    1752     { 
    1753         str = orSTRING( a1 ); 
    1754         orTermCStr( str ); 
    1755         file = orStrChars( str, a1 ); 
    1756  
    1757         fp = fopen( file, "wb" ); 
    1758         if( fp ) 
    1759         { 
    1760             if( ! png_save( fp, (OImage*) bin->buf ) ) 
    1761             { 
    1762                 orError( "png save failed" ); 
    1763             } 
    1764             fclose( fp ); 
    1765         } 
    1766     } 
    1767 } 
    1768  
    1769  
    1770 UR_CALL( toImageNative ) 
    1771 { 
    1772     if( a1->RESTYPE == RES_TYPE_FONT ) 
    1773     { 
    1774         FontResource* res = gxFont( a1->index ); 
    1775         if( res && orHoldIsValid(res->imgHold) ) 
    1776         { 
    1777             orResult( OT_IMAGE, orHoldIndex( res->imgHold ) ); 
    1778         } 
    1779     } 
    1780 } 
    1781  
    1782  
    1783 //---------------------------------------------------------------------------- 
    1784  
    1785  
    1786 TextureResource* createTexture() 
    1787 { 
    1788     TextureResource* tr = memAlloc( sizeof(TextureResource) ); 
    1789     if( tr ) 
    1790     { 
    1791         tr->res.resType = RES_TYPE_TEXTURE; 
    1792         //tr->name    = 0; 
    1793         tr->imgHold = OR_INVALID_HOLD; 
    1794         tr->glTexId = 0; 
    1795     } 
    1796     return tr; 
    1797 } 
    1798  
    1799  
    1800 void destroyTexture( Resource* res ) 
    1801 { 
    1802     TextureResource* tr = (TextureResource*) res; 
    1803     if( res ) 
    1804     { 
    1805         //if( tr->name ) 
    1806         //    memFree( tr->name ); 
    1807  
    1808         if( orHoldIsValid(tr->imgHold) ) 
    1809             orRelease( tr->imgHold ); 
    1810  
    1811         if( tr->glTexId ) 
    1812             glDeleteTextures( 1, &tr->glTexId ); 
    1813  
    1814         memFree( res ); 
    1815     } 
    1816 } 
    1817  
    1818  
    1819 extern void destroyDrawList( Resource* ); 
    1820 extern void destroyFont( Resource* ); 
    1821  
    1822  
    1823 ResourceClass resourceClasses[ RES_TYPE_COUNT ] = 
    1824 { 
    1825     { RES_TYPE_TEXTURE,  destroyTexture  }, 
    1826     { RES_TYPE_DRAWLIST, destroyDrawList }, 
    1827     { RES_TYPE_FONT,     destroyFont     } 
    1828 }; 
    1829  
    1830  
    1831 Resource* gxFindResource( int type, const char* name, int len ) 
    1832 { 
    1833     uint32_t key = resd_hash( name, len ); 
    1834     return gxFindResourceKey( type, key ); 
    1835 } 
    1836  
    1837  
    1838 Resource* gxFindResourceKey( int type, uint32_t key ) 
    1839 { 
    1840     Resource* res; 
    1841     res = resd_lookup( &gEnv.resd, key ); 
    1842     if( res && (res->resType == type) ) 
    1843         return res; 
    1844     return 0; 
    1845 } 
    1846  
    1847  
    1848 //---------------------------------------------------------------------------- 
    1849  
    1850  
    1851 /* 
    1852 static void addContextWord( OContext* ctx, OWordRef* word, const char* name ) 
    1853 { 
    1854     int len = strlen( name ); 
    1855     word->context = orContextN( ctx ); 
    1856     word->index   = orIntern( ctx, name, len ); 
    1857     word->atom    = orInternAtom( name, len ); 
    1858 } 
    1859 */ 
    1860  
    1861  
    1862   "widget: context [\n" 
    1863   "  parent:\n" 
    1864   "  children: none\n" 
    1865   "  x: 0.0\n" 
    1866   "  y: 0.0\n" 
    1867   "  w: 1.0\n" 
    1868   "  h: 1.0\n" 
    1869   "  mouse-move:\n" 
    1870   "  mouse-down:\n" 
    1871   "  mouse-up:\n" 
    1872   "  mouse-wheel:\n" 
    1873   "  key-down:\n" 
    1874   "  key-up:\n" 
    1875   "  render: none\n" 
    1876   "]\n" 
    1877   "render-dialect: [\n" 
    1878   "  0  ['call integer!]\n" 
    1879   "  1  ['call block!]\n" 
    1880   "  2  ['push matrix!]\n" 
    1881   "  3  ['push]\n" 
    1882   "  4  ['pop]\n" 
    1883   "  5  ['trans vec3!]\n" 
    1884   "  6  ['rotate number! vec3!]\n" 
    1885   "  7  ['scale vec3!]\n" 
    1886   "  7  ['scale number!]\n" 
    1887   "  8  [tuple!]\n" 
    1888   "  9  ['pen pair!]\n" 
    1889   " 10  ['pen 'current]\n" 
    1890   " 11  ['font issue!]\n" 
    1891   " 12  ['text string!]\n" 
    1892   " 13  ['text get-word!]\n" 
    1893   " 14  ['verts   block!]\n" 
    1894   " 15  ['normals block!]\n" 
    1895   " 16  ['colors  block!]\n" 
    1896   " 17  ['uvs     block!]\n" 
    1897   " 18  ['quads  word! block!]\n" 
    1898   " 19  ['tris   word! block!]\n" 
    1899   " 20  ['strip  word! block!]\n" 
    1900   " 21  ['fan    word! block!]\n" 
    1901   " 22  ['points word! block!]\n" 
    1902   " 23  ['lines  word! block!]\n" 
    1903   " 24  ['point-size number!]\n" 
    1904   " 25  ['texture integer! file!]\n" 
    1905   " 26  ['light integer! 'on]\n" 
    1906   " 27  ['light integer! 'off]\n" 
    1907   " 28  ['light integer! vec3!]\n" 
    1908   "]\n" 
    1909   "joystick-port: context [\n" 
    1910   "  scheme: 'joystick\n" 
    1911   "  name:\n" 
    1912   "  fd: none\n" 
    1913   "  axis-count:\n" 
    1914   "  button-count: 0\n" 
    1915   "  input: none\n" 
    1916   "]\n" 
    1917   "protect 'widget\n" 
    1918   "protect 'render-dialect\n" 
    1919   "protect 'joystick-port\n" 
    1920   "compile-gl:    native [blk [block!]]\n" 
    1921   "render-prog:   native [name [issue! resource!] blk [block!]]\n" 
    1922   "call:          native [list [integer! resource!]]\n" 
    1923   "display:       native [mode [integer! pair!] /window]\n" 
    1924   "display-modes: native []\n" 
    1925   "clear-color:   native [color [tuple! none!]]\n" 
    1926   "exec:          native [what]\n" 
    1927   "play:          native [snd [file! sound!]]\n" 
    1928   "silence:       native [snd]\n" 
    1929   "push:          native []\n" 
    1930   "pop:           native []\n" 
    1931   "translate:     native [x y z]\n" 
    1932   "scale:         native [x y z]\n" 
    1933   "push-matrix:   native [m [matrix!]]\n" 
    1934   "ortho-view:    native [\n" 
    1935   "  widget [object!]\n" 
    1936   "  size   [none! pair!]\n" 
    1937   "  center [none! matrix! vec3!]\n" 
    1938   "]\n" 
    1939   "viewport:      native [widget [object!] cam [none! matrix!]]\n" 
    1940   "render-state:  native [val]\n" 
    1941   "render-text:   native [pos val]\n" 
    1942   "move:          native [pos x y z]\n" 
    1943   "rotate:        native [m axis angle]\n" 
    1944   "key-repeat:    native [state [logic!]]\n" 
    1945   "screengrab:    native []\n" 
    1946   "mouse-handler: native [blk [block!]]\n" 
    1947   "key-handler:   native [blk [block!]]\n" 
    1948   "hash:          native [name [string! issue!]]\n" 
    1949   "resource:      native [name [integer! issue!]]\n" 
    1950   "resource-group: native [id [word! integer!] /free]\n" 
    1951   "save:          native [file [file!] img [image!]]\n" 
    1952   "make-texfont:  native [\n" 
    1953   "  name    [string! issue!]\n" 
    1954   "  file    [file!]\n" 
    1955   "  pntsize [integer!]\n" 
    1956   "  /glyphs codes [string!]\n" 
    1957   "  /dim    size [integer! pair!] ]\n" 
    1958   "to-image:  native [val [resource!]]\n" 
    1959   "x-axis: make vec3! [1.0 0.0 0.0]\n" 
    1960   "y-axis: make vec3! [0.0 1.0 0.0]\n" 
    1961   "z-axis: make vec3! [0.0 0.0 1.0]\n" 
    1962   "identity: make matrix! none\n" 
    1963   ; 
    1964 #endif 
    1965  
    1966  
    19671312static char _gxBoot[] = 
    19681313  "[file string! -- data][\n" 
     
    19781323extern void uc_load_wav( UThread*, UCell* ); 
    19791324extern void uc_load_png( UThread*, UCell* ); 
     1325extern void uc_save_png( UThread*, UCell* ); 
    19801326 
    19811327static UCallDef _gxCalls[] = 
     
    19861332    { uc_display_swap,   "display.swap" }, 
    19871333    { uc_display_area,   "display.area" }, 
     1334    { uc_display_snap,   "display.snapshot" }, 
    19881335    { uc_key_repeat,     "key-repeat" }, 
    19891336    { uc_key_code,       "key-code" }, 
    19901337    { uc_load_png,       "load.png" }, 
     1338    { uc_save_png,       "save.png" }, 
    19911339    { uc_load_wav,       "load.wav" }, 
    19921340    { uc_display,        "display" }, 
  • trunk/thune/gl/gx.h

    r310 r321  
    165165 
    166166 
    167 UIndex ur_makeRaster( UCell*, int format, int w, int h ); 
     167UIndex ur_makeRaster( UCell*, int format, int w, int h, UBinary** ); 
    168168 
    169169#define ur_rastHead(c)      ((RasterHead*) ur_bin(c)->ptr.v) 
    170 #define ur_rasterElem(bin)  (bin->ptr.b + sizeof(RasterHead)) 
     170#define ur_rastElem(bin)    ((bin)->ptr.b + sizeof(RasterHead)) 
    171171 
    172 #define ur_fontRast(c)      ((UCellRasterFont*) c)->rasterN 
    173 #define ur_fontTF(c)        ((UCellRasterFont*) c)->fontN 
    174 #define ur_fontTexId(c)     ((UCellRasterFont*) c)->glTexId 
     172#define ur_fontRast(c)      ((UCellRasterFont*) (c))->rasterN 
     173#define ur_fontTF(c)        ((UCellRasterFont*) (c))->fontN 
     174#define ur_fontTexId(c)     ((UCellRasterFont*) (c))->glTexId 
    175175 
    176 #define ur_texRast(c)       ((UCellTexture*) c)->rasterN 
    177 #define ur_texId(c)         ((UCellTexture*) c)->glTexId 
    178 #define ur_texPool(c)       ((UCellTexture*) c)->glTexIdPool 
     176#define ur_texRast(c)       ((UCellTexture*) (c))->rasterN 
     177#define ur_texId(c)         ((UCellTexture*) (c))->glTexId 
     178#define ur_texPool(c)       ((UCellTexture*) (c))->glTexIdPool 
    179179 
    180 #define ur_fboId(c)         ((UCellTexture*) c)->glTexId 
    181 #define ur_fboPool(c)       ((UCellTexture*) c)->glTexIdPool 
     180#define ur_fboId(c)         ((UCellTexture*) (c))->glTexId 
     181#define ur_fboPool(c)       ((UCellTexture*) (c))->glTexIdPool 
    182182 
    183183 
  • trunk/thune/gl/gx_dt.c

    r316 r321  
    4343 
    4444 
    45 UIndex ur_makeRaster( UCell* res, int format, int w, int h ) 
     45/** 
     46  \return Binary index and initialied res.  If binp is non-zero, it is set. 
     47*/ 
     48UIndex ur_makeRaster( UCell* res, int format, int w, int h, UBinary** binp ) 
    4649{ 
    4750    UIndex binN; 
     
    6467    ur_setSeries( res, binN, 0 ); 
    6568 
     69    if( binp ) 
     70        *binp = bin; 
     71 
    6672    return binN; 
    6773} 
     
    9096 
    9197            ur_makeRaster( res, format, 
    92                            tos->coord.elem[0], tos->coord.elem[1] ); 
     98                           tos->coord.elem[0], tos->coord.elem[1], 0 ); 
    9399 
    94100            UR_S_DROP; 
     
    98104    ur_throwErr( UR_ERR_DATATYPE, "raster! make expected coord!" ); 
    99105} 
     106 
     107 
     108#if 0 
     109// (raster! val -- raster) 
     110UR_CALL( to_raster ) 
     111{ 
     112    //printf( "KR to-raster\n" ); 
     113    if( ur_is(tos, UT_TEXTURE) ) 
     114    { 
     115    } 
     116 
     117    UR_S_DROP;