StackOverflow에서 몇 가지 게시물을 사용하여 프레임 버퍼를 사용하여 간단한 렌더링 - 텍스처를 만들었습니다.framebuffer를 사용하여 텍스처로 렌더링하려고하면 항상 흰색 텍스처가 발생합니다.
문제는 작동하지 않는다는 것입니다. 내 마지막 질감은 흰색 사각형이므로 뭔가가 잘못되었습니다. 나는 gl 오류를 전혀 얻지 못하고있다. 여기 내 코드가있다.
인스턴스 변수를 선언하십시오.
GLuint texture;
GLuint textureFrameBuffer;
텍스처와 프레임 버퍼를 생성하십시오.
glGetError();
//Generate the texture that we will draw to (saves us a lot of processor).
glEnable(GL_TEXTURE_2D);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Use OpenGL ES to generate a name for the texture.
// Pass by reference so that our texture variable gets set.
glGenTextures(1, &texture);
// Bind the texture name.
glBindTexture(GL_TEXTURE_2D, texture);
// Specify a 2D texture image, providing a pointer to the image data in memory.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
//Create a frame buffer to draw to. This will allow us to directly edit the texture.
GLint oldFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
glGenFramebuffersOES(1, &textureFrameBuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, texture, 0);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO);
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
NSLog(@"Error on framebuffer init. glError: 0x%04X", err);
}
큰 문자열을 프레임 버퍼에 그립니다.
glGetError();
GLint oldFBO;
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, &oldFBO);
//Bind our frame buffer.
glBindFramebufferOES(GL_FRAMEBUFFER_OES, textureFrameBuffer);
//Clear out the texture.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Draw the letters to the frame buffer. (calls glDrawArrays a bunch of times, binds various textures, etc.) Does everything in 2D.
[self renderDialog:displayString withSprite:displaySprite withName:displaySpriteName];
//Unbind the frame buffer.
glBindFramebufferOES(GL_FRAMEBUFFER_OES, oldFBO);
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
NSLog(@"Error on string creation. glError: 0x%04X", err);
}
그리기.
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glGetError();
//Draw the text.
[EAGLView enable2D];
//Push the matrix so we can keep it as it was previously.
glPushMatrix();
//Store the coordinates/dimensions from the rectangle.
float x = 0;
float y = [Globals getPlayableHeight] - dialogRect.size.height;
float w = [Globals getPlayableWidth];
float h = dialogRect.size.height;
// Set up an array of values to use as the sprite vertices.
GLfloat vertices[] =
{
x, y,
x, y+h,
x+w, y+h,
x+w, y
};
// Set up an array of values for the texture coordinates.
GLfloat texcoords[] =
{
0, 0,
0, h/128,
w/512, h/128,
w/512, 0
};
//Render the vertices by pointing to the arrays.
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
// Set the texture parameters to use a linear filter when minifying.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Allow transparency and blending.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Enable 2D textures.
glEnable(GL_TEXTURE_2D);
//Bind this texture.
[EAGLView bindTexture:texture];
//Finally draw the arrays.
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
//Restore the model view matrix to prevent contamination.
glPopMatrix();
GLenum err = glGetError();
if (err != GL_NO_ERROR)
{
NSLog(@"Error on draw. glError: 0x%04X", err);
}
다른 모든 것들은 다른 컨텍스트에서 잘 작동합니다. 어떤 아이디어? Framebuffers에 대해서는 거의 알지 못하므로 문제 해결에 도움이 될 것입니다.
시도해 보겠습니다. 이전에 실제로 완료 확인을 했었고 사실이었습니다. 위 코드에 포함하지 않았습니다. 이 프레임 버퍼가 완료되면 모든 것이 제대로 작동한다는 것을 의미하지는 않는다고 가정합니다. 또한, 내가 GL_TEXTURE_MIN_FILTER에 대해 당신을 따르는 지 확신하지 못한다. glGenTextures (첫 번째 코드 블록 참조)를 호출하기 전에이를 설정했다. – Eli
각 텍스처에는 고유 한 축소/확대 기능과 랩 모드가 있습니다. glTexParameterf를 호출하면 함수가 호출 될 때 현재 바인딩 된 텍스처에만 영향을줍니다. 렌더링하는 텍스처에 대한 축소 함수를 변경하려면 텍스처를 만들고 바인딩 한 후 glTexParameterf를 호출해야합니다. 프레임 버퍼 완성도는 특정 케이스와 관련이없는 것처럼 들리지만,보다 이국적인 프레임 버퍼 객체 구성을 염두에 두는 것이 좋습니다. – Pivot