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

📄 macvideo.cpp

📁 英特尔&#174 线程构建模块(英特尔&#174 TBB)是一个屡获殊荣的 C++ 运行时库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                glBegin (GL_TRIANGLE_STRIP); // draw either tri strips of line strips                    glTexCoord2f (startXTexCoord, startYTexCoord); // draw upper left in world coordinates                    glVertex3d (startXDraw, startYDraw, 0.0);                    glTexCoord2f (endXTexCoord, startYTexCoord); // draw lower left in world coordinates                    glVertex3d (endXDraw, startYDraw, 0.0);                    glTexCoord2f (startXTexCoord, endYTexCoord); // draw upper right in world coordinates                    glVertex3d (startXDraw, endYDraw, 0.0);                    glTexCoord2f (endXTexCoord, endYTexCoord); // draw lower right in world coordinates                    glVertex3d (endXDraw, endYDraw, 0.0);                glEnd();                            }            //////////////////////            glReportError (); // report any errors            offsetY += currTextureHeight; // offset drawing position for next texture vertically        }        offsetX += currTextureWidth; // offset drawing position for next texture horizontally    }    glReportError (); // report any errors    glDisable (textureTarget); // done with texturing            aglSwapBuffers (pWindowInfo->aglContext);}// finds the minimum OpenGL capabilites across all displays and GPUs attached to machine.static void FindMinimumOpenGLCapabilities (pRecGLCap pOpenGLCaps){    WindowPtr pWin = NULL;     Rect rectWin = {0, 0, 10, 10};    GLint attrib[] = { AGL_RGBA, AGL_NONE };    AGLPixelFormat fmt = NULL;    AGLContext ctx = NULL;    GLint deviceMaxTextureSize = 0, NPOTDMaxTextureSize = 0;        if (NULL != gpOpenGLCaps)    {        // init desired caps to max values        pOpenGLCaps->f_ext_texture_rectangle = true;        pOpenGLCaps->f_ext_client_storage = true;        pOpenGLCaps->f_ext_packed_pixel = true;        pOpenGLCaps->f_ext_texture_edge_clamp = true;        pOpenGLCaps->f_gl_texture_edge_clamp = true;        pOpenGLCaps->maxTextureSize = 0x7FFFFFFF;        pOpenGLCaps->maxNOPTDTextureSize = 0x7FFFFFFF;        // build window        pWin = NewCWindow (0L, &rectWin, NULL, false,                plainDBox, (WindowPtr) -1L, true, 0L);                        // build context        fmt = aglChoosePixelFormat(NULL, 0, attrib);        if (fmt)            ctx = aglCreateContext(fmt, NULL);        if (ctx)        {            GDHandle hgdNthDevice;                        aglSetDrawable(ctx, GetWindowPort (pWin));            aglSetCurrentContext(ctx);                        // for each display            hgdNthDevice = GetDeviceList ();            while (hgdNthDevice)            {                if (TestDeviceAttribute (hgdNthDevice, screenDevice))                    if (TestDeviceAttribute (hgdNthDevice, screenActive))                    {                        // move window to display                        MoveWindow (pWin, (**hgdNthDevice).gdRect.left + 5, (**hgdNthDevice).gdRect.top + 5, false);                        aglUpdateContext(ctx);                                                // for each cap (this can obviously be expanded)                        // if this driver/GPU/display is less capable                            // save this minimum capability                        {                            // get strings                            enum { kShortVersionLength = 32 };                            const GLubyte * strVersion = glGetString (GL_VERSION); // get version string                            const GLubyte * strExtension = glGetString (GL_EXTENSIONS);    // get extension string                                                        // get just the non-vendor specific part of version string                            GLubyte strShortVersion [kShortVersionLength];                            short i = 0;                            while ((((strVersion[i] <= '9') && (strVersion[i] >= '0')) || (strVersion[i] == '.')) && (i < kShortVersionLength)) // get only basic version info (until first space)                                strShortVersion [i] = strVersion[i++];                            strShortVersion [i] = 0; //truncate string                                                        // compare capabilities based on extension string and GL version                            pOpenGLCaps->f_ext_texture_rectangle =                                 pOpenGLCaps->f_ext_texture_rectangle && (NULL != strstr ((const char *) strExtension, "GL_EXT_texture_rectangle"));                            pOpenGLCaps->f_ext_client_storage =                                 pOpenGLCaps->f_ext_client_storage && (NULL != strstr ((const char *) strExtension, "GL_APPLE_client_storage"));                            pOpenGLCaps->f_ext_packed_pixel =                                 pOpenGLCaps->f_ext_packed_pixel && (NULL != strstr ((const char *) strExtension, "GL_APPLE_packed_pixel"));                            pOpenGLCaps->f_ext_texture_edge_clamp =                                 pOpenGLCaps->f_ext_texture_edge_clamp && (NULL != strstr ((const char *) strExtension, "GL_SGIS_texture_edge_clamp"));                            pOpenGLCaps->f_gl_texture_edge_clamp =                                 pOpenGLCaps->f_gl_texture_edge_clamp && (!strstr ((const char *) strShortVersion, "1.0") && !strstr ((const char *) strShortVersion, "1.1")); // if not 1.0 and not 1.1 must be 1.2 or greater                                                        // get device max texture size                            glGetIntegerv (GL_MAX_TEXTURE_SIZE, &deviceMaxTextureSize);                            if (deviceMaxTextureSize < pOpenGLCaps->maxTextureSize)                                pOpenGLCaps->maxTextureSize = deviceMaxTextureSize;                            // get max size of non-power of two texture on devices which support                            if (NULL != strstr ((const char *) strExtension, "GL_EXT_texture_rectangle"))                            {                            #ifdef GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT                                glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &NPOTDMaxTextureSize);                                if (NPOTDMaxTextureSize < pOpenGLCaps->maxNOPTDTextureSize)                                    pOpenGLCaps->maxNOPTDTextureSize = NPOTDMaxTextureSize;                            #endif                            }                        }                        // next display                        hgdNthDevice = GetNextDevice(hgdNthDevice);                    }            }            aglDestroyContext( ctx );        }        else        { // could not build context set caps to min            pOpenGLCaps->f_ext_texture_rectangle = false;            pOpenGLCaps->f_ext_client_storage = false;            pOpenGLCaps->f_ext_packed_pixel = false;            pOpenGLCaps->f_ext_texture_edge_clamp = false;            pOpenGLCaps->f_gl_texture_edge_clamp = false;            pOpenGLCaps->maxTextureSize = 0;        }                // set clamp param based on retrieved capabilities        if (pOpenGLCaps->f_gl_texture_edge_clamp) // if OpenGL 1.2 or later and texture edge clamp is supported natively                    pOpenGLCaps->edgeClampParam = GL_CLAMP_TO_EDGE;  // use 1.2+ constant to clamp texture coords so as to not sample the border color        else if (pOpenGLCaps->f_ext_texture_edge_clamp) // if GL_SGIS_texture_edge_clamp extension supported            pOpenGLCaps->edgeClampParam = GL_CLAMP_TO_EDGE_SGIS; // use extension to clamp texture coords so as to not sample the border color        else            pOpenGLCaps->edgeClampParam = GL_CLAMP; // clamp texture coords to [0, 1]        aglDestroyPixelFormat( fmt );        DisposeWindow( pWin );    }}//--------------------------------------------------------------------------------------------static OSStatusWindowEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon ){    OSStatus    err = eventNotHandledErr;    WindowRef    window = (WindowRef) inRefcon;    if( GetEventClass(inEvent) == kEventClassMouse )    {        Point mousePoint; // UInt32 modifiers;        verify_noerr( GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePoint) );        pRecImage pWindowInfo = (pRecImage) GetWRefCon (window); // get the gl info for the window        if(pWindowInfo) {            SetPortWindowPort(window);            GlobalToLocal (&mousePoint); //convert mouse coordinates to local coordintes prior to recording            mousePoint.h /= pWindowInfo->zoomX; mousePoint.v /= pWindowInfo->zoomY;            if(mousePoint.h >= 0 && mousePoint.h < pWindowInfo->imageWidth && mousePoint.v >= 0 && mousePoint.v < pWindowInfo->imageHeight)                g_video->on_mouse(mousePoint.h, mousePoint.v, GetEventKind(inEvent) == kEventMouseUp?-1:1), err = noErr;        }    }    else if( GetEventClass(inEvent) == kEventClassKeyboard )    {        char ch;        verify_noerr( GetEventParameter( inEvent, kEventParamKeyMacCharCodes, typeChar, NULL, sizeof( ch ), NULL, &ch ) );        if(g_video)            g_video->on_key(ch);    }    else //if( GetEventClass(inEvent) == kEventClassWindow )    {        if (GetEventKind(inEvent) == kEventWindowDrawContent)        {            //DrawGL(window);            err = noErr;        }        else if (GetEventKind(inEvent) == kEventWindowClose)        {            if (window)            {                g_video->running = false;            }            err = noErr;        }        else if (GetEventKind(inEvent) == kEventWindowShowing)        {            err = BuildGLForWindow (window);        }        else if ((GetEventKind(inEvent) == kEventWindowResizeCompleted) || (GetEventKind(inEvent) == kEventWindowDragCompleted))        {            err = ResizeMoveGLWindow (window);        }        else if (GetEventKind(inEvent) == kEventWindowZoomed)        {            err = ResizeMoveGLWindow (window);        }    }        return err;}//--------------------------------------------------------------------------------------------DEFINE_ONE_SHOT_HANDLER_GETTER( WindowEventHandler )//--------------------------------------------------------------------------------------------WindowRef HandleNew(){    OSStatus  err;    WindowRef window;    pRecImage pWindowInfo = NULL;    static const EventTypeSpec    kWindowEvents[] =    {       { kEventClassMouse, kEventMouseUp },       { kEventClassMouse, kEventMouseDown },       { kEventClassKeyboard, kEventRawKeyDown },//       { kEventClassCommand, kEventCommandProcess },       { kEventClassWindow, kEventWindowShowing },       { kEventClassWindow, kEventWindowClose },       { kEventClassWindow, kEventWindowDrawContent },       { kEventClassWindow, kEventWindowResizeCompleted },       { kEventClassWindow, kEventWindowDragCompleted },       { kEventClassWindow, kEventWindowZoomed}    };    if (!gpOpenGLCaps)    {        gpOpenGLCaps = (pRecGLCap) NewPtrClear (sizeof (recGLCap));        FindMinimumOpenGLCapabilities (gpOpenGLCaps);    }    // Create a window. "MainWindow" is the name of the window object. This name is set in     // InterfaceBuilder when the nib is created.    err = CreateWindowFromNib( sNibRef, CFSTR("MainWindow"), &window );    require_noerr( err, CantCreateWindow );    // We don't need the nib reference anymore.    DisposeNibReference(sNibRef);        pWindowInfo = (recImage *) NewPtrClear (sizeof (recImage));    pWindowInfo->textureWidth = pWindowInfo->imageWidth = g_sizex;    pWindowInfo->textureHeight = pWindowInfo->imageHeight = g_sizey;    pWindowInfo->imageDepth = 32;    pWindowInfo->fTileTextures = true;    pWindowInfo->fOverlapTextures = false; // TODO: ???    pWindowInfo->maxTextureSize = gpOpenGLCaps->maxTextureSize;    pWindowInfo->fNPOTTextures = gpOpenGLCaps->f_ext_texture_rectangle;    pWindowInfo->fClientTextures = gpOpenGLCaps->f_ext_client_storage; // texture from client memory if available    pWindowInfo->fAGPTexturing = true; // if AGP texturing selected    pWindowInfo->pImageBuffer = (unsigned char*) g_pImg;    // set default parameters for this image    pWindowInfo->zoomX = 1.0f; // pixel 1 to 1 size    pWindowInfo->zoomY = 1.0f; // pixel 1 to 1 size    SetWRefCon (window, (long) pWindowInfo);    char buffer[256]; buffer[0] = snprintf(buffer+1, 255, "%s", g_video->title);    SetWTitle (window, (ConstStr255Param)buffer);    // Install a command handler on the window. We don't use this handler yet, but ne

⌨️ 快捷键说明

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