Changeset 296 for trunk/thune/gl

Show
Ignore:
Timestamp:
10/06/06 21:47:31 (2 years ago)
Author:
krobillard
Message:

Thune GL - Lighting works.

Location:
trunk/thune/gl
Files:
5 modified

Legend:

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

    r295 r296  
    2121#include <assert.h> 
    2222#include "gx.h" 
     23#include "gx_atoms.h" 
    2324#include "draw_ops.h" 
    2425#include "gllist.h" 
     
    9596            break; 
    9697 
     98        case GRS_MODEL: 
     99            glDepthMask( GL_TRUE ); 
     100            glShadeModel( GL_SMOOTH ); 
     101 
     102            //glColorMaterial( GL_FRONT, GL_DIFFUSE ); 
     103            //glEnable( GL_COLOR_MATERIAL ); 
     104 
     105            glEnable( GL_DEPTH_TEST ); 
     106            glEnable( GL_LIGHTING ); 
     107            glEnable( GL_CULL_FACE ); 
     108 
     109            glDisable( GL_BLEND ); 
     110 
     111            gr_disableTexture(); 
     112            break; 
     113 
    97114        case GRS_TEXT: 
    98115            glDepthMask( GL_FALSE ); 
     
    363380 
    364381 
     382static void _lightv3( GLenum light, GLenum pname, UCell* cell, GLfloat w ) 
     383{ 
     384    GLfloat pos[4]; 
     385 
     386    pos[0] = cell->vec3.xyz[0]; 
     387    pos[1] = cell->vec3.xyz[1]; 
     388    pos[2] = cell->vec3.xyz[2]; 
     389    pos[3] = w; 
     390 
     391    printf( "KR %d %d %g\n", light, pname, w ); 
     392    glLightfv( light, pname, pos );  
     393} 
     394 
     395 
     396static void _lightEn( GLenum light, UCell* cell ) 
     397{ 
     398    if( ur_logic(cell) ) 
     399        glEnable( light ); 
     400    else 
     401        glDisable( light ); 
     402} 
     403 
     404 
     405static void dop_light( UThread* ur_thread, UCell* val, int light ) 
     406{ 
     407    if( ur_is(val, UT_LOGIC) ) 
     408    { 
     409        _lightEn( light, val ); 
     410    } 
     411    else if( ur_is(val, UT_VEC3) ) 
     412    { 
     413        _lightv3( light, GL_POSITION, val, 0.0f ); 
     414    } 
     415    else if( ur_is(val, UT_BLOCK) ) 
     416    { 
     417        UBlock* blk; 
     418        UCell* it; 
     419        UCell* end; 
     420        GLenum name = GL_POSITION; 
     421        GLfloat w = 0.0f; 
     422 
     423        blk = ur_block(val); 
     424        UR_ITER_BLOCK( it, end, blk, val ); 
     425        while( it != end ) 
     426        { 
     427            if( ur_isAWord(it) ) 
     428            { 
     429                switch( ur_atom(it) ) 
     430                { 
     431                    case UR_ATOM_AMBIENT: name = GL_AMBIENT;  w = 1.0f; break; 
     432                    case UR_ATOM_DIFFUSE: name = GL_DIFFUSE;  w = 1.0f; break; 
     433                    case UR_ATOM_POS:     name = GL_POSITION; w = 0.0f; break; 
     434 
     435                    default: 
     436                        val = ur_wordCell( ur_thread, it ); 
     437                        if( val ) 
     438                        { 
     439                            if( ur_is(val, UT_LOGIC) ) 
     440                                _lightEn( light, val ); 
     441                            else if( ur_is(val, UT_VEC3) ) 
     442                                _lightv3( light, name, val, w ); 
     443                        } 
     444                        break; 
     445                } 
     446            } 
     447            else if( ur_is(it, UT_VEC3) ) 
     448            { 
     449                _lightv3( light, name, it, w ); 
     450            } 
     451            else if( ur_is(it, UT_LOGIC) ) 
     452            { 
     453                _lightEn( light, it ); 
     454            } 
     455            ++it; 
     456        } 
     457    } 
     458} 
     459 
    365460 
    366461/* 
     
    470565                break; 
    471566 
    472             case DOP_CAMERA: 
     567            case DOP_MODEL: 
     568                gr_setState( GRS_MODEL ); 
     569                break; 
     570 
     571            case DOP_CAMERA:    // context! 
    473572            { 
    474573                //int ref = ur_selIsAtom(pc) ? ur_sel(pc) : 0; 
     
    478577                    dop_camera( val ); 
    479578            } 
     579                break; 
     580 
     581            case DOP_LIGHT:     // logic!   on/off 
     582                                // vec3!    position 
     583            { 
     584                int light = ur_selIsAtom(pc) ? 0 : ur_sel(pc); 
     585                ++pc; 
     586                VAL_WORD_OR_PC 
     587                dop_light( ur_thread, val, GL_LIGHT0 + light ); 
     588            } 
     589                break; 
     590 
     591            case DOP_LIGHTING:  // logic!   on/off 
     592                ++pc; 
     593                if( ur_is(pc, UT_LOGIC) ) 
     594                { 
     595                    if( ur_logic(val) ) 
     596                        glEnable( GL_LIGHTING ); 
     597                    else 
     598                        glDisable( GL_LIGHTING ); 
     599                } 
    480600                break; 
    481601 
     
    499619                { 
    500620                    glColor3fv( pc->vec3.xyz ); 
     621                  //glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, pc->vec3.xyz ); 
    501622                } 
    502623                else if( ur_is(pc, UT_INT) ) 
  • trunk/thune/gl/draw_ops.h

    r286 r296  
    55#define DOP_CALL            2 
    66#define DOP_SOLID           3 
    7 #define DOP_COLOR           4 
    8 #define DOP_COLORS          5 
    9 #define DOP_VERTS           6 
    10 #define DOP_NORMALS         7 
    11 #define DOP_UVS             8 
    12 #define DOP_POINTS          9 
    13 #define DOP_LINES           10 
    14 #define DOP_LINE_STRIP      11 
    15 #define DOP_TRIS            12 
    16 #define DOP_TRI_STRIP       13 
    17 #define DOP_TRI_FAN         14 
    18 #define DOP_QUADS           15 
    19 #define DOP_QUAD_STRIP      16 
    20 #define DOP_CAMERA          17 
    21 #define DOP_UNIT_XFORM      18 
    22 #define DOP_PUSH            19 
    23 #define DOP_POP             20 
    24 #define DOP_TRANSLATE       21 
    25 #define DOP_ROTATE          22 
    26 #define DOP_SCALE           23 
    27 #define DOP_FONT            24 
    28 #define DOP_TEXT            25 
     7#define DOP_MODEL           4 
     8#define DOP_COLOR           5 
     9#define DOP_COLORS          6 
     10#define DOP_VERTS           7 
     11#define DOP_NORMALS         8 
     12#define DOP_UVS             9 
     13#define DOP_POINTS          10 
     14#define DOP_LINES           11 
     15#define DOP_LINE_STRIP      12 
     16#define DOP_TRIS            13 
     17#define DOP_TRI_STRIP       14 
     18#define DOP_TRI_FAN         15 
     19#define DOP_QUADS           16 
     20#define DOP_QUAD_STRIP      17 
     21#define DOP_CAMERA          18 
     22#define DOP_LIGHT           19 
     23#define DOP_LIGHTING        20 
     24#define DOP_PUSH            21 
     25#define DOP_POP             22 
     26#define DOP_TRANSLATE       23 
     27#define DOP_ROTATE          24 
     28#define DOP_SCALE           25 
     29#define DOP_FONT            26 
     30#define DOP_TEXT            27 
  • trunk/thune/gl/gx.c

    r295 r296  
    18441844    FIXED_ATOM( "mouse-wheel", 11, UR_ATOM_MOUSE_WHEEL ); 
    18451845 
     1846    FIXED_ATOM( "ambient",  7, UR_ATOM_AMBIENT ); 
     1847    FIXED_ATOM( "diffuse",  7, UR_ATOM_DIFFUSE ); 
     1848    FIXED_ATOM( "specular", 8, UR_ATOM_SPECULAR ); 
     1849    FIXED_ATOM( "pos",      3, UR_ATOM_POS ); 
     1850 
    18461851#if MAKE_ATOM_HEADER 
    18471852    exit(0); 
  • trunk/thune/gl/gx.t

    r295 r296  
    9595    call 
    9696    solid 
     97    model 
    9798 
    9899    color 
     
    112113 
    113114    camera 
    114     unit-xform 
     115    light 
     116    lighting 
     117    ;unit-xform 
    115118    push 
    116119    pop 
  • trunk/thune/gl/test.t

    r295 r296  
    106106    ] 
    107107    func :turntable 
     108 
     109    0 0 turntable 
    108110] make :visual-cam 
    109111 
     
    166168    draw-list [ 
    167169        camera visual-cam 
    168         solid 
     170        light   [on 1.0,0.8,1.0] 
     171        light/1 [on -1.0,-0.8,0.0 diffuse 0.8,0.5,0.5] 
     172        model 
    169173        call d7-list 
    170174 
    171175        camera ortho-cam 
     176        lighting off 
    172177        push 
    173178            scale zoom