コード例 #1
0
ファイル: reflection.cpp プロジェクト: jmigual/graphics
bool Reflection::paintGL()
{
    // Pass 1. Draw scene reversed and store it to the texture
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    m_pProgram->bind();
    m_pProgram->setUniformValue("factor", (float)-1.0);
    m_pProgram->setUniformValue("texture", false);
    m_pProgram->setUniformValue("colorMap", 0);
    m_pProgram->setUniformValue("SIZE", QVector2D(glwidget()->width(), glwidget()->height()));
    
    Box b = scene()->boundingBox();
    m_pProgram->setUniformValue("radius", b.radius());
    m_pProgram->setUniformValue("boundingMin", b.min());
    m_pProgram->setUniformValue("boundingMax", b.max());
    
    m_pProgram->setUniformValue("modelViewProjectionMatrix",
                                camera()->projectionMatrix() *
                                camera()->modelviewMatrix());
    m_pProgram->setUniformValue("modelViewMatrix", camera()->modelviewMatrix());
    m_pProgram->setUniformValue("normalMatrix", camera()->modelviewMatrix().normalMatrix());

    // Ligth specs
    m_pProgram->setUniformValue("lightAmbient", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("lightDiffuse", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("lightSpecular", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("lightPosition", QVector4D(100., 100., 100., 1.));

    m_pProgram->setUniformValue("matAmbient", QVector4D(.5, .4, .0, 1.));
    m_pProgram->setUniformValue("matDiffuse", QVector4D(.5, .4, .0, 1.));
    m_pProgram->setUniformValue("matSpecular", QVector4D(1., 1., 1., 1.));
    m_pProgram->setUniformValue("matShininess", (float) 30.);

    drawPlugin()->drawScene();

    // Get texture
    glBindTexture(GL_TEXTURE_2D, m_textureId);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, glwidget()->width(), glwidget()->height());
    glGenerateMipmap(GL_TEXTURE_2D);

    // Pass 2 Draw Scene normal
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    m_pProgram->setUniformValue("factor", (float)1.0);

    
    drawPlugin()->drawScene();

    // Pass 3 Draw quad using texture
    m_pProgram->setUniformValue("texture", true);
    glBindVertexArray(m_VAO_rect);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glBindVertexArray(0);

    m_pProgram->release();
    glBindTexture(GL_TEXTURE_2D, 0);

    return true;
}
コード例 #2
0
ファイル: glowing.cpp プロジェクト: jmigual/graphics
bool Glowing::paintGL()
{
  // Pass 1. Draw scene
  glClearColor(0,0,0,0);
  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  drawPlugin()->drawScene();
  
  // Get texture
  glBindTexture(GL_TEXTURE_2D, textureId);
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
  glGenerateMipmap(GL_TEXTURE_2D);
  
  // Pass 2. Draw quad using texture
  glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  program->bind();
  program->setUniformValue("colorMap", 0);
  program->setUniformValue("SIZE", float(IMAGE_WIDTH));  
  
  // quad covering viewport 
  program->setUniformValue("modelViewProjectionMatrix", QMatrix4x4() );  
  
  drawRect();
  program->release();
  glBindTexture(GL_TEXTURE_2D, 0);
  
  return true;
}
コード例 #3
0
ファイル: BasicPlugin.c プロジェクト: tmm08a/SafariCrashes
int16_t NPP_HandleEvent(NPP instance, void* event)
{
  NPCocoaEvent* cocoaEvent = (NPCocoaEvent*)event;
  if (cocoaEvent && (cocoaEvent->type == NPCocoaEventDrawRect)) {
    drawPlugin(instance, (NPCocoaEvent*)event);
    return 1;
  }

  return 0;
}
コード例 #4
0
int16_t NavigationPlugin::handleEvent(const ANPEvent* evt) {
    NPP instance = this->inst();

    switch (evt->eventType) {
        case kDraw_ANPEventType:
            switch (evt->data.draw.model) {
                case kBitmap_ANPDrawingModel:
                    drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
                    return 1;
                default:
                    break;   // unknown drawing model
            }
            break;

        case kLifecycle_ANPEventType:
            if (evt->data.lifecycle.action == kLoseFocus_ANPLifecycleAction) {
                gLogI.log(kDebug_ANPLogType, "----%p Loosing Focus", instance);
                m_hasFocus = false;
                inval(instance);
                return 1;
            }
            else if (evt->data.lifecycle.action == kGainFocus_ANPLifecycleAction) {
                gLogI.log(kDebug_ANPLogType, "----%p Gaining Focus", instance);
                m_hasFocus = true;
                inval(instance);
                return 1;
            }
            break;

        case kMouse_ANPEventType:
            return 1;

        case kKey_ANPEventType:
            if (evt->data.key.action == kDown_ANPKeyAction) {
            	bool result = handleNavigation(evt->data.key.nativeCode);
            	inval(instance);
            	return result;
            }
            return 1;

        default:
            break;
    }
    return 0;   // unknown or unhandled event
}
コード例 #5
0
ファイル: AudioPlugin.cpp プロジェクト: XilongPei/Elastos5
int16_t AudioPlugin::handleEvent(const ANPEvent* evt) {
    //NPP instance = this->inst();

    gLogI.log(kError_ANPLogType, "AudioPlugin::handleEvent:%d, action:%d", evt->eventType, evt->data.touch.action);
    switch (evt->eventType) {
        case kDraw_ANPEventType:
            switch (evt->data.draw.model) {
                case kBitmap_ANPDrawingModel:
                    drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
                    return 1;
                default:
                    break;   // unknown drawing model
            }

        case kTouch_ANPEventType:
        case kMultiTouch_ANPEventType:
            {
            int x = evt->data.touch.x;
            int y = evt->data.touch.y;
            gLogI.log(kError_ANPLogType, "kTouch_ANPEventType:x:%d, y%d", x, y);
            if (kDown_ANPTouchAction == evt->data.touch.action) {

                m_activeTouchRect = validTouch(x,y);
                if(m_activeTouchRect) {
                    m_activeTouch = true;
                    return 1;
                }

            } else if (kUp_ANPTouchAction == evt->data.touch.action && m_activeTouch) {
                handleTouch(x, y);
                m_activeTouch = false;
                return 1;
            } else if (kCancel_ANPTouchAction == evt->data.touch.action) {
                m_activeTouch = false;
            }
            break;
        }
        default:
            break;
    }
    return 0;   // unknown or unhandled event
}
コード例 #6
0
int16_t FormPlugin::handleEvent(const ANPEvent* evt) {
    NPP instance = this->inst();

    switch (evt->eventType) {
    case kDraw_ANPEventType:
        switch (evt->data.draw.model) {
        case kBitmap_ANPDrawingModel:
            drawPlugin(evt->data.draw.data.bitmap, evt->data.draw.clip);
            return 1;
        default:
            break;   // unknown drawing model
        }
        break;

    case kLifecycle_ANPEventType:
        if (evt->data.lifecycle.action == kLoseFocus_ANPLifecycleAction) {
            gLogI.log(kDebug_ANPLogType, "----%p Loosing Focus", instance);

            if (m_activeInput) {
                // hide the keyboard
                gWindowI.showKeyboard(instance, false);

                //reset the activeInput
                m_activeInput = NULL;
            }

            m_hasFocus = false;
            inval(instance);
            return 1;
        }
        else if (evt->data.lifecycle.action == kGainFocus_ANPLifecycleAction) {
            gLogI.log(kDebug_ANPLogType, "----%p Gaining Focus", instance);
            m_hasFocus = true;
            inval(instance);
            return 1;
        }
        break;

    case kMouse_ANPEventType: {

        int x = evt->data.mouse.x;
        int y = evt->data.mouse.y;
        if (kDown_ANPMouseAction == evt->data.mouse.action) {

            TextInput* currentInput = validTap(x,y);

            if (currentInput)
                gWindowI.showKeyboard(instance, true);
            else if (m_activeInput)
                gWindowI.showKeyboard(instance, false);

            if (currentInput != m_activeInput)
                switchActiveInput(currentInput);

            return 1;
        }
        break;
    }

    case kKey_ANPEventType:
        if (evt->data.key.action == kDown_ANPKeyAction) {

            //handle navigation keys
            if (evt->data.key.nativeCode >= kDpadUp_ANPKeyCode
                    && evt->data.key.nativeCode <= kDpadCenter_ANPKeyCode) {
                return handleNavigation(evt->data.key.nativeCode) ? 1 : 0;
            }

            if (m_activeInput) {
                handleTextInput(m_activeInput, evt->data.key.nativeCode,
                                evt->data.key.unichar);
                inval(instance, m_activeInput->rect, true);
            }
        }
        return 1;

    default:
        break;
    }
    return 0;   // unknown or unhandled event
}