This post was updated on .
Hi,
I am trying to render texture using Frame Buffer Objects. It is not working to display RGB pixels. My implemented JOGl code as below. Please let me know where I am doing wrong. import java.awt.Graphics; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; import javax.media.opengl.DebugGL2; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.awt.GLCanvas; import javax.media.opengl.awt.GLJPanel; import javax.media.opengl.glu.GLU; import com.jogamp.common.nio.Buffers; import com.jogamp.opengl.util.FPSAnimator; //// Using Textures. public class ofi_vc_video_gl_panel extends GLJPanel { static { try { System.loadLibrary("native_get_frame"); // Catches exception. } catch (UnsatisfiedLinkError e) { System.out.println("Did nt Loaded............." + e); } } /** * */ private static final long serialVersionUID = 1L; //animator animatr = null; static FPSAnimator animatr = null; File file = null; static int user_index = 0; FileWriter fw = null; BufferedWriter bw = null; jni_get_frame get_frm = new jni_get_frame(); public ofi_vc_video_gl_panel (int vid_width, int vid_height, GLCapabilities gl_cap) { super(gl_cap); file = new File("vid_comp_" + user_index + ".txt"); user_index++; // if file doesnt exists, then create it if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { fw = new FileWriter(file.getAbsoluteFile()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } bw = new BufferedWriter(fw); setSize(vid_width, vid_height); setIgnoreRepaint(true); //setDoubleBuffered(true); //setOpaque(true); addGLEventListener(new GLEventListener() { int user_Id = 0; ByteBuffer buff = ByteBuffer.allocateDirect(320*240*3); IntBuffer texture_id = IntBuffer.allocate(1); IntBuffer pbo = IntBuffer.allocate(1); private FloatBuffer t_buff = null;; private FloatBuffer v_buff = null; private IntBuffer renderbuffers = IntBuffer.allocate(1); private IntBuffer framebuffers = IntBuffer.allocate(1); public void reshape(GLAutoDrawable draw, int arg1, int arg2, int width, int height) { // TODO Auto-generated method stub draw.getGL().getGL2().glViewport(0, 0, width, height); } public void init(GLAutoDrawable draw) { user_Id = ofi_vc_video_gl_panel.user_index; get_frm.native_get_frame(ofi_vc_video_gl_panel.user_index); // TODO Auto-generated method stub GL2 gl = draw.getGL().getGL2(); gl.glClearColor(0.f, 0.f, 0.f, 0.f); gl.glViewport(0, 0, 320, 240); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrthof(0.f, 320.f, 240.f, 0.f, 1.0f, -1.0f); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glDisable(GL2.GL_STENCIL_TEST); gl.glShadeModel(GL2.GL_SMOOTH); gl.setSwapInterval(0); gl.glGenRenderbuffers(1, renderbuffers); gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, renderbuffers.get(0)); gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_DEPTH_COMPONENT, 320, 240); gl.glGenTextures(1, texture_id); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glBindTexture(GL2.GL_TEXTURE_2D, texture_id.get(0)); gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1); gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, 3, 320, 240 , 0, GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, buff); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP_TO_EDGE); gl.glGenerateMipmap(GL2.GL_TEXTURE_2D); gl.glGenFramebuffers(1, framebuffers); gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, framebuffers.get(0)); gl.glFramebufferTexture2D(GL2.GL_DRAW_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0, GL2.GL_TEXTURE_2D, texture_id.get(0), 0); gl.glFramebufferRenderbuffer(GL2.GL_DRAW_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT, GL2.GL_RENDERBUFFER, renderbuffers.get(0)); int status = gl.glCheckFramebufferStatus(GL2.GL_DRAW_FRAMEBUFFER); if (status == GL2.GL_FRAMEBUFFER_COMPLETE) { System.out.println("Frame Buffer good"); } else { System.out.println("Frame buffer not good"); } gl.glBindTexture(GL2.GL_TEXTURE_2D, 0); gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, 0); gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, 0); float [] v_arr = new float[8]; v_arr[0] = 0.f; v_arr[1] = 0.f; v_arr[2] = 320.f; v_arr[3] = 0.f; v_arr[4] = 320.f; v_arr[5] = 240.f; v_arr[6] = 0.f; v_arr[7] = 240.f; float [] t_arr = new float[8]; t_arr[0] = 0.f; t_arr[1] = 1.f; t_arr[2] = 1.f; t_arr[3] = 1.f; t_arr[4] = 1.f; t_arr[5] = 0.f; t_arr[6] = 0.f; t_arr[7] = 0.f; v_buff = Buffers.newDirectFloatBuffer(v_arr); t_buff = Buffers.newDirectFloatBuffer(t_arr); int err = gl.glGetError(); if (err != GL2.GL_NO_ERROR) { System.out.println("OpenGL error 9::" + " " + err); } } public void dispose(GLAutoDrawable draw) { // TODO Auto-generated method stub } public void display(GLAutoDrawable draw) { buff.clear(); boolean frm_got = get_frm.get_frame(buff, user_Id); if (frm_got) { GL2 gl = draw.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); gl.glLoadIdentity(); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glBindTexture(GL2.GL_TEXTURE_2D, texture_id.get(0)); gl.glPixelStorei(GL2.GL_UNPACK_ALIGNMENT, 1); gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, 3, 320, 240 , 0, GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, buff); gl.glGenerateMipmap(GL2.GL_TEXTURE_2D); gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, framebuffers.get(0)); gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl.glVertexPointer(2, GL2.GL_FLOAT, 0, v_buff); gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, t_buff); gl.glDrawArrays(GL2.GL_QUADS, 0, 4); draw.getGL().getGL2().glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); draw.getGL().getGL2().glDisableClientState(GL2.GL_VERTEX_ARRAY); gl.glBindTexture(GL2.GL_TEXTURE_2D, 0); gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, 0); draw.swapBuffers(); int err = gl.glGetError(); if (err != GL2.GL_NO_ERROR) { System.out.println("Error in gl::" + err); } } try { bw.write(" " + System.currentTimeMillis()); bw.write('\n'); bw.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); if (animatr == null) { animatr = new FPSAnimator(this, 100, true); } else { animatr.add(this); } } public void start () { setVisible(true); animatr.start(); } } Regards, anand |
Free forum by Nabble | Edit this page |