Ich habe versucht ein gutes tutorial fuer das FBO zu finden. Jedoch habe ich nur solche gefunden wo es fuer 3D ist oder in c++ geschrieben ist. Das Problem dabei ist, dass ich in c++ nicht programmieren kann und auch noch nicht in 3D.
Im OpenGL bin ich nur ein anfänger. Ich habe es mit diesen beispielen versucht zu verstehen:
Tutorial 14 : Render To Texture | opengl-tutorial.org
Tutorial 14 : Render To Texture | opengl-tutorial.org
Render to Texture with Frame Buffer Objects (FBO) - LWJGL
Mein letzter versuch endete so:
:rtfm: ---> ;(
Meine frage an euch ist, ob ihr mir einen tutorial empfehlen würdet der genau fuer dass ist wozu ich ihn brauche. Oder ob ihr mir einen source code schreibt mit einer guten kommentaren-//erklärung
Ich ferstehe nicht wie ich dass FBO erstellen soll und es am bildschirm zeigen soll und naturliech wie ich rein zeichne. Danke fuer euere hilfe und tut mir leid wegen meiner deutschen gramatik.
Im OpenGL bin ich nur ein anfänger. Ich habe es mit diesen beispielen versucht zu verstehen:
Tutorial 14 : Render To Texture | opengl-tutorial.org
Tutorial 14 : Render To Texture | opengl-tutorial.org
Render to Texture with Frame Buffer Objects (FBO) - LWJGL
Mein letzter versuch endete so:
Code:
package fbo2dtutorial2;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;
import static org.lwjgl.opengl.ARBFramebufferObject.*;
import static org.lwjgl.opengl.EXTFramebufferObject.*;
import static org.lwjgl.opengl.GL11.*;
/**
*
*
*/
public class FBO2dTutorial2 {
public static int dispHeight = 600, dispWidth = 800;
static int colorTextureID;
static int framebufferID;
static int depthRenderBufferID;
public static void main(String[] args)
{
initDisplay();
initGL();
initLoop();
cleanUp();
}
private static void initLoop()
{
while (!Display.isCloseRequested())
{
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Logger.getLogger(FBO2dTutorial2.class.getName()).log(Level.SEVERE, null, ex);
}
glBegin(GL_QUADS);
glVertex2f(0.0f, 0.0f);System.out.println("Kreslím bod A");
glVertex2f(1.0f, 0.0f);System.out.println("Kreslím bod B");
glVertex2f(1.0f, 1.0f);System.out.println("Kreslím bod C");
glVertex2f(0.0f, 1.0f);System.out.println("Kreslím bod D");
glEnd();
renderToFBO();
}
}
private static void renderToFBO()
{
glBindTexture(GL_TEXTURE_2D, 0); // unlink textures because if we dont it all is gonna fail
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID); // switch to rendering on our FBO
System.out.println("Kreslím");
glClearColor (1.0f, 0.0f, 0.0f, 0.5f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer on the fbo to red
glLoadIdentity (); // Reset The Modelview Matrix
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex2f( 1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex2f( 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, 1.0f); // Top Left Of The Texture and Quad
glEnd();
glDisable(GL_TEXTURE_2D);
glFlush ();
}
/******************************************************************************/
private static void cleanUp() {
Display.destroy();
}
private static void initGL() {
glMatrixMode(GL_PROJECTION); //zvolili sme si projekcny matrix
glLoadIdentity(); //zresetovali sme pamať matrixu
glOrtho(0,Display.getWidth(),0, Display.getHeight(), -1, 1); // zvolili sme si typ zobrazenia a velkosť videnej plochy
glMatrixMode(GL_MODELVIEW); //zvolili sme si modelview matrix
glClearColor(0,0,0,1); //nastavenie farby pozadia/ničoho na danu hodnotu
glDisable(GL_DEPTH_TEST); //Deaktivovali sme Depth test pretože nebudeme pracovatť v 3D
glEnable(GL_TEXTURE_2D);
/***************/
initFBO();
}
private static void initDisplay() {
try {
Display.setDisplayMode(new DisplayMode(dispWidth,dispHeight));
Display.create();
Display.setVSyncEnabled(true);
}
catch (LWJGLException ex) {
Logger.getLogger(FBO2dTutorial2.class.getName()).log(Level.SEVERE, null, ex);
}
glColor3f(1,1,0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);System.out.println("Kreslím bod 1");
glTexCoord2f(1.0f, 0.0f);System.out.println("Kreslím bod 2");
glTexCoord2f(1.0f, 1.0f);System.out.println("Kreslím bod 3");
glTexCoord2f(0.0f, 1.0f);System.out.println("Kreslím bod 4");
glEnd();
}
private static void initFBO() {
// check if GL_EXT_framebuffer_object can be use on this system
if (!GLContext.getCapabilities().GL_EXT_framebuffer_object) {
System.out.println("FBO not supported!!!");
System.exit(0);
}
else {
System.out.println("FBO is supported!!!");
// init our fbo
framebufferID = glGenFramebuffersEXT(); // create a new framebuffer
colorTextureID = glGenTextures(); // and a new texture used as a color buffer
//depthRenderBufferID = glGenRenderbuffersEXT(); // And finally a new depthbuffer
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferID); // switch to the new framebuffer
// initialize color texture
glBindTexture(GL_TEXTURE_2D, colorTextureID); // Bind the colorbuffer texture
glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA8, 500, 400, 0,GL_RGBA, GL_INT, (java.nio.ByteBuffer) null); // Give an empty image to OpenGL
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Poor filtering. Needed !
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // Poor filtering. Needed !
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, colorTextureID, 0); // attach it to the framebuffer
// Always check that our framebuffer is ok
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
System.out.println("pojebalo sa to");
glViewport(0,0,500,400);
}
}
}
:rtfm: ---> ;(
Meine frage an euch ist, ob ihr mir einen tutorial empfehlen würdet der genau fuer dass ist wozu ich ihn brauche. Oder ob ihr mir einen source code schreibt mit einer guten kommentaren-//erklärung
Ich ferstehe nicht wie ich dass FBO erstellen soll und es am bildschirm zeigen soll und naturliech wie ich rein zeichne. Danke fuer euere hilfe und tut mir leid wegen meiner deutschen gramatik.