FileDocCategorySizeDatePackage
FlatRenderer.javaAPI DocFobs4JMF API 0.4.18536Wed Jun 22 18:53:52 BST 2005com.omnividea.media.renderer.video.opengl

FlatRenderer

public class FlatRenderer extends Object implements RenderEventListener
FOBS Java CrossPlatform JMF PlugIn Copyright (c) 2004 Omnividea Multimedia S.L This file is part of FOBS. FOBS is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. FOBS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with FOBS; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Fields Summary
int
width
int
height
int[]
textures
private int[]
firstpixels
private int
formatWidth
private int
formatHeight
private int[]
data
private float
extendX
private float
extendY
private int
inputColorOrder
private int
inputFormat
private net.java.games.cg.CGcontext
cgContext
private net.java.games.cg.CGprogram
cgProgram
private net.java.games.cg.CGparameter
cgParameter
private String
program
Constructors Summary
public FlatRenderer()

 

      
        inputColorOrder = com.omnividea.media.parser.video.Parser.isBigEndian()?GL.GL_RGBA:GL.GL_BGRA;
        inputFormat = com.omnividea.media.parser.video.Parser.isBigEndian()?GL.GL_UNSIGNED_INT_8_8_8_8:GL.GL_UNSIGNED_INT_8_8_8_8_REV;
    
Methods Summary
public voiddisplay(net.java.games.jogl.GLDrawable drawable)

        GL gl = drawable.getGL();
        GLU glu = drawable.getGLU();
        
        if(data != null) {
            gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0, formatWidth, formatHeight,  inputColorOrder, inputFormat, data);
        }
                
        gl.glBegin(GL.GL_QUADS);
	        gl.glTexCoord2f(0,0);
	        gl.glVertex3d(-1, 1,0);
	        gl.glTexCoord2f(extendX,0);
	        gl.glVertex3d(1, 1,0);
	        gl.glTexCoord2f(extendX,extendY);
	        gl.glVertex3d(1, -1,0);
	        gl.glTexCoord2f(0,extendY);
	        gl.glVertex3d(-1, -1,0);
        gl.glEnd();
        
        drawable.swapBuffers();
          
        
 
        
    
public voiddisplayChanged(net.java.games.jogl.GLDrawable arg0, boolean arg1, boolean arg2)

    
public intgetBestProfile()

        if(CgGL.cgGLIsProfileSupported(CgGL.CG_PROFILE_ARBFP1))
        {
            return CgGL.CG_PROFILE_ARBFP1;
        }    
        else
        {
            return CgGL.CG_PROFILE_FP20;
        }
    
public booleanhasFragmentShaderSupport()

        if(CgGL.cgGLIsProfileSupported(CgGL.CG_PROFILE_FP20)||CgGL.cgGLIsProfileSupported(CgGL.CG_PROFILE_ARBFP1))
        {
            return true;
        }
        else return false;
    
public voidinit(net.java.games.jogl.GLDrawable drawable)

        System.out.println("init 3d");
        
        
        
        
        GL gl = drawable.getGL();
        GLU glu = drawable.getGLU();
        gl.glGenTextures(1, textures);
        gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);
        gl.glDisable(GL.GL_DEPTH_TEST);
        gl.glDisable(GL.GL_LIGHTING);
        gl.glEnable(GL.GL_TEXTURE_2D);
        //gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);

        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
        gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);

        gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0,  GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8, (char[])null);

        //System.out.println("time :: " + (System.currentTimeMillis() - time));  
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glMatrixMode(GL.GL_PROJECTION);    
        gl.glLoadIdentity();               
        glu.gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
        
        cgContext = CgGL.cgCreateContext();
        int errorCg = CgGL.cgGetError();
        System.out.println("cgCreateContext: "+CgGL.cgGetErrorString(errorCg));

        if(hasFragmentShaderSupport())
        {
            
            cgProgram = CgGL.cgCreateProgram(cgContext,  CgGL.CG_SOURCE, program,  getBestProfile(),  "main",  null);
            //errorCg = CgGL.cgGetError();
            //System.out.println("cgCreateProgram: "+CgGL.cgGetErrorString(errorCg));
            
            CgGL.cgGLLoadProgram(cgProgram);
            //errorCg = CgGL.cgGetError();
            //System.out.println("cgLoadProgram: "+CgGL.cgGetErrorString(errorCg));
            CgGL.cgGLBindProgram(cgProgram);
            //errorCg = CgGL.cgGetError();
            //System.out.println("cgBindPRogram: "+CgGL.cgGetErrorString(errorCg));
            
            cgParameter = CgGL.cgGetNamedParameter(cgProgram,  "Y");
            CgGL.cgGLSetTextureParameter(cgParameter,  textures[0]);
            //errorCg = CgGL.cgGetError();
            //System.out.println("cgSetParam: "+CgGL.cgGetErrorString(errorCg));
            
            CgGL.cgGLEnableTextureParameter(cgParameter);

            gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);
            CgGL.cgGLEnableProfile(getBestProfile());
            //errorCg = CgGL.cgGetError();
            //System.out.println("cgEnableProfile: "+CgGL.cgGetErrorString(errorCg));
        }
        else
        {
            FobsConfiguration.videoFrameFormat=FobsConfiguration.RGBA;
            inputColorOrder = GL.GL_BGRA;
            inputFormat = GL.GL_UNSIGNED_INT_8_8_8_8_REV;
            System.out.println("Your graphics hardware is not capable of doing Color Space Conversion\n");
        }
    
public voidmouseClicked(java.awt.event.MouseEvent e)

public voidmouseDragged(java.awt.event.MouseEvent e)


    
public voidmouseMoved(java.awt.event.MouseEvent e)

public voidreshape(net.java.games.jogl.GLDrawable drawable, int x, int y, int width, int height)

    
public voidsetFormat(int videoWidth, int videoHeight)

        formatWidth = videoWidth;
        formatHeight = videoHeight;      
        extendX = ((float) formatWidth)/width;
        extendY = ((float) formatHeight)/height;

    
public voidsetRenderingData(int[] data)

        this.data = data;