⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r_opengl.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef MINI_GL_COMPATIBILITY    glGetIntegerv(GL_VIEWPORT, viewport);     glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);#endif}// -----------------+// SetStates        : Set permanent states// -----------------+void SetStates( void ){    // Bind little white RGBA texture to ID NOTEXTURE_NUM.    FUINT Data[8*8];    int i;    DBG_Printf( "SetStates()\n" );    // Hurdler: not necessary, is it?    //glShadeModel( GL_SMOOTH );      // iterate vertice colors    glShadeModel( GL_FLAT );    glEnable( GL_TEXTURE_2D );      // two-dimensional texturing    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );    glAlphaFunc( GL_NOTEQUAL, 0 );    //glDisable( GL_ALPHA_TEST );     // enable alpha testing    //glBlendFunc( GL_ONE, GL_ZERO ); // copy pixel to frame buffer (opaque)    glEnable( GL_BLEND );           // enable color blending    glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );//    glDisable(GL_DITHER);         // faB: ??? (undocumented in OpenGL 1.1)                                  // Hurdler: yes, it is!    glEnable( GL_DEPTH_TEST );    // check the depth buffer    //glDepthMask( 1 );             // enable writing to depth buffer    glClearDepth( 1.0 );    glDepthRange( 0.0, 1.0 );    glDepthFunc(GL_LEQUAL);    // this set CurrentPolyFlags to the acctual configuration    CurrentPolyFlags = 0xffffffff;    SetBlend(0);    for(i=0; i<64; i++ )        Data[i] = 0xffFFffFF;       // white pixel    tex_downloaded = -1;    SetNoTexture();    //glBindTexture( GL_TEXTURE_2D, NOTEXTURE_NUM );    //tex_downloaded = NOTEXTURE_NUM;    //glTexImage2D( GL_TEXTURE_2D, 0, 4, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, Data );    glPolygonOffset(-1.0, -1.0);    //glEnable(GL_CULL_FACE);    //glCullFace(GL_FRONT);    //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);    //glPolygonMode(GL_FRONT, GL_LINE);    //glFogi(GL_FOG_MODE, GL_EXP);    //glHint(GL_FOG_HINT, GL_NICEST);    //glFogfv(GL_FOG_COLOR, fogcolor);    //glFogf(GL_FOG_DENSITY, 0.0005);    // bp : when no t&l :)    glLoadIdentity();    glScalef(1.0, 1.0f, -1.0f);#ifndef MINI_GL_COMPATIBILITY    glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); // added for new coronas' code (without depth buffer)#endif}// -----------------+// Flush            : flush OpenGL textures//                  : Clear list of downloaded mipmaps// -----------------+void Flush( void ){    //DBG_Printf ("HWR_Flush()\n");    while( gr_cachehead )    {        // ceci n'est pas du tout necessaire vu que tu les a charger normalement et        // donc il sont dans ta liste !#if 0        //Hurdler: 25/04/2000: now support colormap in hardware mode        FTextureInfo    *tmp = gr_cachehead->nextskin;        // The memory should be freed in the main code        while (tmp)        {            glDeleteTextures( 1, &tmp->downloaded );            tmp->downloaded = 0;            tmp = tmp->nextcolormap;        }#endif        glDeleteTextures( 1, &gr_cachehead->downloaded );        gr_cachehead->downloaded = 0;        gr_cachehead = gr_cachehead->nextmipmap;    }    gr_cachetail = gr_cachehead = NULL; //Hurdler: well, gr_cachehead is already NULL    NextTexAvail = FIRST_TEX_AVAIL;    tex_downloaded = 0;}// -----------------+// isExtAvailable   : Look if an OpenGL extension is available// Returns          : true if extension available// -----------------+int isExtAvailable(char *extension){    const GLubyte   *start;    GLubyte         *where, *terminator;    where = (GLubyte *) strchr(extension, ' ');    if (where || *extension == '\0')        return 0;    start = gl_extensions;    for (;;) {        where = (GLubyte *) strstr((const char *) start, extension);        if (!where)            break;        terminator = where + strlen(extension);        if (where == start || *(where - 1) == ' ')            if (*terminator == ' ' || *terminator == '\0')                return 1;        start = terminator;    }    return 0;}// -----------------+// Init             : Initialise the OpenGL interface API// Returns          :// -----------------+EXPORT boolean HWRAPI( Init ) (I_Error_t FatalErrorFunction){    I_Error_GL = FatalErrorFunction;    DBG_Printf ("%s v%d.%d%s\n", DRIVER_STRING, VERSION/100, VERSION%100, VERSIONSTRING);    return 1;}// -----------------+// ClearMipMapCache : Flush OpenGL textures from memory// -----------------+EXPORT void HWRAPI( ClearMipMapCache ) ( void ){    // DBG_Printf ("HWR_Flush(exe)\n");    Flush();}// -----------------+// ReadRect         : Read a rectangle region of the truecolor framebuffer//                  : store pixels as 16bit 565 RGB// Returns          : 16bit 565 RGB pixel array stored in dst_data// -----------------+EXPORT void HWRAPI( ReadRect ) (int x, int y, int width, int height,                                int dst_stride, unsigned short * dst_data){    // DBG_Printf ("ReadRect()\n");    GLubyte *image;    int i, j;    image = (GLubyte *) malloc(width*height*3*sizeof(GLubyte));    glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);    for (i=height-1; i>=0; i--)        for (j=0; j<width; j++)            dst_data[(height-1-i)*width+j] =                                  ((image[(i*width+j)*3]>>3)<<11) |                                  ((image[(i*width+j)*3+1]>>2)<<5) |                                  ((image[(i*width+j)*3+2]>>3));    free(image);}// -----------------+// GClipRect        : Defines the 2D hardware clipping window// -----------------+EXPORT void HWRAPI( GClipRect ) (int minx, int miny, int maxx, int maxy, float nearclip){    // DBG_Printf ("GClipRect(%d, %d, %d, %d)\n", minx, miny, maxx, maxy);    glViewport( minx, screen_height-maxy, maxx-minx, maxy-miny );    NEAR_CLIPPING_PLANE = nearclip;    //glScissor(minx, screen_height-maxy, maxx-minx, maxy-miny);    glMatrixMode( GL_PROJECTION );    glLoadIdentity();    // pas ok pour le mode "small window/status bar"    if ((maxx/(maxy-miny)) >= 2)                // splitscreen        gluPerspective( 53.13, 2*ASPECT_RATIO,  // 53.13 = 2*atan(0.5)                        NEAR_CLIPPING_PLANE, FAR_CLIPPING_PLANE);    else                                        // single        gluPerspective( fov, ASPECT_RATIO, NEAR_CLIPPING_PLANE, FAR_CLIPPING_PLANE);    glMatrixMode(GL_MODELVIEW);    // added for new coronas' code (without depth buffer)#ifndef MINI_GL_COMPATIBILITY    glGetIntegerv(GL_VIEWPORT, viewport);    glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);#endif}// -----------------+// ClearBuffer      : Clear the color/alpha/depth buffer(s)// -----------------+EXPORT void HWRAPI( ClearBuffer ) ( FBOOLEAN ColorMask,                                    FBOOLEAN DepthMask,                                    FRGBAFloat * ClearColor ){    // DBG_Printf ("ClearBuffer(%d)\n", alpha);    FUINT   ClearMask = 0;    if( ColorMask ) {        if( ClearColor )            glClearColor( ClearColor->red,                          ClearColor->green,                          ClearColor->blue,                          ClearColor->alpha );        ClearMask |= GL_COLOR_BUFFER_BIT;    }    if( DepthMask ) {        //glClearDepth( 1.0 );     //Hurdler: all that are permanen states        //glDepthRange( 0.0, 1.0 );        //glDepthFunc( GL_LEQUAL );        ClearMask |= GL_DEPTH_BUFFER_BIT;    }    SetBlend( DepthMask ? PF_Occlude | CurrentPolyFlags : CurrentPolyFlags&~PF_Occlude );    glClear( ClearMask );}// -----------------+// HWRAPI Draw2DLine: Render a 2D line// -----------------+EXPORT void HWRAPI( Draw2DLine ) ( F2DCoord * v1,                                   F2DCoord * v2,                                   RGBA_t Color ){    FRGBAFloat c;    // DBG_Printf ("DrawLine() (%f %f %f) %d\n", v1->x, -v1->y, -v1->oow, v1->argb);#ifdef MINI_GL_COMPATIBILITY    GLfloat x1, x2, x3, x4;    GLfloat y1, y2, y3, y4;    GLfloat dx, dy;    GLfloat angle;#endif    // BP: we should reflect the new state in our variable    //SetBlend( PF_Modulated|PF_NoTexture );    glDisable( GL_TEXTURE_2D );    c.red   = byte2float[Color.s.red];    c.green = byte2float[Color.s.green];    c.blue  = byte2float[Color.s.blue];    c.alpha = byte2float[Color.s.alpha];#ifndef MINI_GL_COMPATIBILITY    glColor4fv( (float *)&c );    // is in RGBA float format    glBegin(GL_LINES);        glVertex3f(v1->x, -v1->y, 1);        glVertex3f(v2->x, -v2->y, 1);    glEnd();#else    if( v2->x != v1->x )        angle = (float)atan((v2->y-v1->y)/(v2->x-v1->x));    else        angle = N_PI_DEMI;    dx = (float)sin(angle) / (float)screen_width;    dy = (float)cos(angle) / (float)screen_height;    x1 = v1->x - dx;  y1 = v1->y + dy;    x2 = v2->x - dx;  y2 = v2->y + dy;    x3 = v2->x + dx;  y3 = v2->y - dy;    x4 = v1->x + dx;  y4 = v1->y - dy;    glColor4f(c.red, c.green, c.blue, c.alpha);    glBegin( GL_TRIANGLE_FAN );        glVertex3f( x1, -y1, 1 );        glVertex3f( x2, -y2, 1 );        glVertex3f( x3, -y3, 1 );        glVertex3f( x4, -y4, 1 );    glEnd();#endif    glEnable( GL_TEXTURE_2D );}// -----------------+// SetBlend         : Set render mode// -----------------+// PF_Masked - we could use an ALPHA_TEST of GL_EQUAL, and alpha ref of 0,//             is it faster when pixels are discarded ?EXPORT void HWRAPI( SetBlend ) ( FBITFIELD PolyFlags ){    FBITFIELD   Xor = CurrentPolyFlags^PolyFlags;    if( Xor & ( PF_Blending|PF_Occlude|PF_NoTexture|PF_Modulated|PF_NoDepthTest|PF_Decal|PF_Invisible|PF_NoAlphaTest ) )    {        if( Xor&(PF_Blending) ) // if blending mode must be changed        {            switch(PolyFlags & PF_Blending) {                case PF_Translucent & PF_Blending:                     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // alpha = level of transparency                     break;                case PF_Masked & PF_Blending:                     // Hurdler: does that mean lighting is only made by alpha src?                     // it sounds ok, but not for polygonsmooth                     glBlendFunc( GL_SRC_ALPHA, GL_ZERO );                // 0 alpha = holes in texture                     break;                case PF_Additive & PF_Blending:#ifdef ATI_RAGE_PRO_COMPATIBILITY                     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // alpha = level of transparency#else                     glBlendFunc( GL_SRC_ALPHA, GL_ONE );                 // src * alpha + dest#endif                     break;                case PF_Environment & PF_Blending:                     glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );                     break;                case PF_Substractive & PF_Blending:                     // not realy but what else ?                     glBlendFunc( GL_ZERO, GL_ONE_MINUS_SRC_COLOR);                     break;                default : // must be 0, otherwise it's an error                     // No blending                     glBlendFunc( GL_ONE, GL_ZERO );   // the same as no blending                     break;            }        }        if( Xor & PF_NoAlphaTest)        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -