void drawComponentBuffer()
    {
       #if ! JUCE_ANDROID
        glEnable (GL_TEXTURE_2D);
        clearGLError();
       #endif
        context.extensions.glActiveTexture (GL_TEXTURE0);
        glBindTexture (GL_TEXTURE_2D, cachedImageFrameBuffer.getTextureID());

        const Rectangle<int> cacheBounds (cachedImageFrameBuffer.getWidth(), cachedImageFrameBuffer.getHeight());
        context.copyTexture (cacheBounds, cacheBounds, cacheBounds.getWidth(), cacheBounds.getHeight());
        glBindTexture (GL_TEXTURE_2D, 0);
        JUCE_CHECK_OPENGL_ERROR
    }
void OpenGLHelpers::drawTriangleStrip (const GLfloat* const vertices, const GLfloat* const textureCoords, const int numVertices) noexcept
{
   #if ! JUCE_ANDROID
    glEnable (GL_TEXTURE_2D);
    clearGLError();
   #endif
    glDisableClientState (GL_COLOR_ARRAY);
    glDisableClientState (GL_NORMAL_ARRAY);
    glEnableClientState (GL_VERTEX_ARRAY);
    glVertexPointer (2, GL_FLOAT, 0, vertices);
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer (2, GL_FLOAT, 0, textureCoords);
    glDrawArrays (GL_TRIANGLE_STRIP, 0, numVertices);
}
bool
AndroidGraphicBuffer::Bind()
{
  if (!EnsureInitialized())
    return false;

  if (!EnsureEGLImage()) {
    LOG("No valid EGLImage!");
    return false;
  }

  clearGLError();
  sGLFunctions.fImageTargetTexture2DOES(GL_TEXTURE_2D, mEGLImage);
  return ensureNoGLError("glEGLImageTargetTexture2DOES");
}
Ejemplo n.º 4
0
    bool renderFrame()
    {
        ScopedPointer<MessageManagerLock> mmLock;

        const bool isUpdating = needsUpdate.compareAndSetBool (0, 1);

        if (context.renderComponents && isUpdating)
        {
            mmLock = new MessageManagerLock (this);  // need to acquire this before locking the context.
            if (! mmLock->lockWasGained())
                return false;
        }

        if (! context.makeActive())
            return false;

        NativeContext::Locker locker (*nativeContext);

        JUCE_CHECK_OPENGL_ERROR

        if (context.renderer != nullptr)
        {
            glViewport (0, 0, viewportArea.getWidth(), viewportArea.getHeight());
            context.renderer->renderOpenGL();
            clearGLError();
        }

        if (context.renderComponents)
        {
            if (isUpdating)
            {
                paintComponent();
                mmLock = nullptr;
            }

            glViewport (0, 0, viewportArea.getWidth(), viewportArea.getHeight());
            drawComponentBuffer();
        }

        context.swapBuffers();
        return true;
    }
Ejemplo n.º 5
0
    bool renderFrame()
    {
        if (! context.makeActive())
            return false;

        NativeContext::Locker locker (*nativeContext);

        JUCE_CHECK_OPENGL_ERROR
        glViewport (0, 0, component.getWidth(), component.getHeight());

        if (context.renderer != nullptr)
        {
            context.renderer->renderOpenGL();
            clearGLError();
        }

        if (context.renderComponents)
            paintComponent();

        context.swapBuffers();
        return true;
    }
Ejemplo n.º 6
0
/**
  Draw a tree.

  \param node Node
  \param draw_blends If true, only objects that use blending are drawn. Otherwise objects with
         blending are not drawn.
  \return True if the tree contained one or more objects that use blending
 */
bool GLRenderInstance::drawNode(WorldObject& node, bool draw_blends)
{
  double M[16];
  BoundingBox bb;
  vec3d bmin, bmax, t, d;
  bool render_flag = true;
  bool res = false;

  WorldObject::ChildIterator it;
  for(it=node.childsBegin(); it!=node.childsEnd(); it++)
  {
    glPushMatrix();
    // Set the local transformation
    it->second->localTransform().toList(M);
    glMultMatrixd(M);
    // Draw the geom (if visible)
    boost::shared_ptr<GeomObject> geom = it->second->getGeom();
    if (geom.get()!=0 && (it->second->visible.getValue()))
    {
      // Render by default if draw_blends is false
      render_flag = !draw_blends;

      // Set material
      boost::shared_ptr<Material> mat = it->second->getMaterial();
      Material* bmat = dynamic_cast<Material*>(mat.get());
      // Check if the object should be postponed because blending is used...
      if (bmat!=0)
      {
        if (bmat->usesBlending())
        {
          res = true;
          render_flag = draw_blends;
        }
      }

      if (render_flag)
      {
        // Set material
        glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT);
        if (bmat!=0)
        {
          bmat->applyGL();
        }

        if (draw_solid)
        {
          clearGLError();
          geom->drawGL();
        }
        // Draw bounding box
        if (draw_bboxes)
        {
          bb = geom->boundingBox();
          if (!bb.isEmpty())
          {
            glDisable(GL_LIGHTING);
            bb.getBounds(bmin, bmax);
            t = 0.5*(bmax+bmin);
            d = bmax-bmin;
            glPushMatrix();
            glTranslated(t.x, t.y, t.z);
            drawWireCube(d.x, d.y, d.z);
            glPopMatrix();
            glEnable(GL_LIGHTING);
          }
        }
        glPopAttrib();  // restore material
      }
    }
    // Draw the children
    res |= drawNode(*(it->second), draw_blends);
    glPopMatrix();
  }
  return res;
}
Ejemplo n.º 7
0
/**
  Draw the current scene.

  \todo Lichtquellen am Anfang disablen
 */
void GLRenderInstance::paint(WorldObject& root)
{
  double M[16];

  if (stereo_mode==2)
  {
    // Switch to both back buffers for initialization...
    glDrawBuffer(GL_BACK);
  }

  // Viewport
  glViewport(viewx, viewy, viewwidth, viewheight);

  // Initialize
  glClearColor(GLfloat(clearcol.x), GLfloat(clearcol.y), GLfloat(clearcol.z), GLfloat(clearcol.w));
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);
//  glDisable(GL_LIGHTING);
  glEnable(GL_LIGHTING);
  glEnable(GL_NORMALIZE);
  if (smooth_model)
    glShadeModel(GL_SMOOTH);
  else
    glShadeModel(GL_FLAT);

  // Enable backface culling
  if (backface_culling)
  {
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
  }
  else
    glDisable(GL_CULL_FACE);

//  glEnable(GL_COLOR_MATERIAL);
  glColorMaterial(GL_FRONT, GL_DIFFUSE);

  if (separate_specular_color)
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
  else
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
  
  clearGLError();  // GL_LIGHT_MODEL_COLOR_CONTROL is not supported in OpenGL 1.1

  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
//  glEnable(GL_LINE_SMOOTH);
//  glEnable(GL_BLEND);
//  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//  glDisable(GL_LIGHTING)
  switch(polygon_mode)
  {
   case 0: glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); break;
   case 1: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break;
   case 2: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); break;
  }

  // Projection
  glMatrixMode(GL_PROJECTION);
  projectionmatrix.toList(M, false);
  glLoadMatrixd(M);

  // Initialize ModelView matrix
  glMatrixMode(GL_MODELVIEW);

  switch(stereo_mode)
  {
   case 1: glViewport(viewx, viewy, viewwidth/2, viewheight); break;
   case 2: glDrawBuffer(GL_BACK_LEFT); break;
  }

  // Draw the scene
  drawScene(root, viewmatrix1);

  switch(stereo_mode)
  {
   case 1:
     // Draw right image
     glViewport(viewx+viewwidth/2, viewy, viewwidth/2, viewheight);
     drawScene(root, viewmatrix2);
     break;
   case 2:
     glDrawBuffer(GL_BACK_RIGHT);
     // Draw right image
     glClear(GL_DEPTH_BUFFER_BIT);
     drawScene(root, viewmatrix2);
     glDrawBuffer(GL_BACK);
     break;
  }

  // Draw the orientation as a small coordinate system in the lower left corner
  if (draw_orientation)
  {
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glViewport(0, 0, 48, 48);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1,1,-1,1,-1,1);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    if (left_handed)
      glScaled(-1,1,1);

    glScalef(GLfloat(0.9), GLfloat(0.9), GLfloat(0.9));
    glRotated(180,0,1,0);
    mat4d V2(viewmatrix1);
    V2.setColumn(3, 0,0,0,1);
    V2.toList(M, false);
    glMultMatrixd(M);

    drawCoordSystem();

    if (stereo_mode==1)
    {
      glViewport(viewwidth/2, 0, 48, 48);
      drawCoordSystem();
    }
  }

  // HUD-Test
/*  glViewport(viewx, viewy, viewwidth, viewheight);
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glDisable(GL_NORMALIZE);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0,1, 0,1, -1, 1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glColor3d(0,1,0);
  glBegin(GL_LINES);
  glVertex2d(0,0);
  glVertex2d(1,1);
  glEnd();*/

  clearGLError();  // final cleanup 
}