I've tried to implement deferred shading but the gbuffer can't store any floating point numbers. The edges from the lighting is VERY rough since the framebuffer can't store negative components for the normals eventhough i passed in the correct internal format and data type.
Example picture of the rough edges
Texture generation:
public TextureResource(int width, int height, int filter, int internalFormat, int format, boolean clamp, int dataType, ByteBuffer data) {
id = glGenTextures();
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, dataType, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
if(clamp) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glBindTexture(GL_TEXTURE_2D, 0);
}
Framebuffer generation:
this.width = width;
this.height = height;
this.attachments = attachments;
boolean hasDepth = false;
IntBuffer drawBuffers = Util.createIntBuffer(attachments.length);
assert(attachments.length <= MAX_ATTACHMENTS);
framebuffer = glGenFramebuffers();
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
for(int i = 0; i < attachments.length; i++) {
if(attachments[i].getAttachmentType() == GL_DEPTH_ATTACHMENT) {
drawBuffers.put(GL_NONE);
hasDepth = true;
} else {
drawBuffers.put(attachments[i].getAttachmentType());
}
if(attachments[i].getAttachmentType() == GL_NONE) {
continue;
}
attachments[i].createTexture(width, height);
glFramebufferTexture2D(GL_FRAMEBUFFER, attachments[i].getAttachmentType(), GL_TEXTURE_2D, attachments[i].getTexture().getId(), 0);
}
if(!hasDepth) {
renderbuffer = glGenRenderbuffers();
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
}
drawBuffers.flip();
glDrawBuffers(drawBuffers);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
System.err.println("Framebuffer creation failed!");
System.exit(1);
}
GBuffer:
super(width, height, new FramebufferAttachment(GL_COLOR_ATTACHMENT1, GL_NEAREST, GL_RGB32F, GL_RGB, false, GL_FLOAT),
new FramebufferAttachment(GL_COLOR_ATTACHMENT0, GL_NEAREST, GL_RGB32F, GL_RGB, false, GL_FLOAT),
new FramebufferAttachment(GL_COLOR_ATTACHMENT2, GL_NEAREST, GL_RGB, GL_RGB, false, GL_UNSIGNED_BYTE));
Geometry pass fragment shader:
#version 330 core
in vec3 worldPos0;
in vec2 texCoord0;
in vec3 normal0;
layout (location = 0) out vec3 gWorldPos;
layout (location = 1) out vec3 gNormal;
layout (location = 2) out vec3 gColor;
uniform sampler2D diffuse;
void main() {
gWorldPos = worldPos0;
gNormal = normalize(normal0);
gColor = texture(diffuse, texCoord0).xyz;
}
It's because it is 3.3 core. OpenGL standard somewhat contradicts itself on the matter of what format are renderable, some implementations actually support RGBxF formats. OpenGL 4.4 specs declare them renderable.
Ifit is really needed, I think is it possible to map integer values to floating point. Ofc you still have limited amount of values, but you can implement negative and fraction values, while having limited range
Related
Environment is Android/OpenGLES2.0
I'm refactoring a 2-dimensional gaussian blur into 2 1-dimensional ones, using a horizontal & vertical pass, as described in: http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/. This is blurring a video from a SurfaceTexture.
I understand that this can be accomplished with framebuffers, and have implemented these with the required steps, however I cannot get the blur to display.
Any help would be greatly appreciated, logging removed in code for clarity.
Framebuffer setup, setupFramebuffers() is called:
int[] newFbo = new int[2];
int[] newTex = new int[2];
void setupFramebuffers() {
createFramebuffer(newFbo, newTex, 0);
createFramebuffer(newFbo, newTex, 1);
GLES20.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
}
void createFramebuffer(int[] fbo, int[] fbtex, int offset) {
GLES20.glGenTextures(1, fbtex, offset);
GLES20.glBindTexture(GL_TEXTURE_2D, fbtex[offset]);
GLES20.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, null);
GLES20.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GLES20.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLES20.glGenFramebuffers(1, fbo, offset);
GLES20.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[offset]);
GLES20.glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbtex[offset], 0);
int status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
switch (status) {
case GL_FRAMEBUFFER_COMPLETE:
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
return;
default:
return;
}
}
In the draw method, generateFbos() is called:
private synchronized void drawToWindow() {
for(ShaderSurfaceView shaderSurfaceView : this.shaderSurfaceViewsToRender) {
if(!shaderSurfaceView.getStopRendering()) {
final int program = shaderSurfaceView.getProgramId();
final WindowSurface windowSurface = shaderSurfaceView.getWindowSurface();
if (windowSurface == null) {
continue;
}
windowSurface.makeCurrent();
GLES20.glViewport(0, 0, windowSurface.getWidth(), windowSurface.getHeight());
generateFbos(shaderSurfaceView, windowSurface);
GLES20.glEnable(GLES20.GL_BLEND);
windowSurface.swapBuffers();
}
}
}
generateFbos:
void generateFbos(ShaderSurfaceView shaderSurfaceView, WindowSurface windowSurface) {
final int positionHandle = shaderSurfaceView.getPositionHandle();
final int textureHandle = shaderSurfaceView.getTextureHandle();
final int mvpMatrixHandle = shaderSurfaceView.getMvpMatrixHandle();
final int stMatrixHandle = shaderSurfaceView.getStMatrixHandle();
final int verticalProgramId = shaderSurfaceView.getVerticalProgramId();
final int horizontalProgramId = shaderSurfaceView.getHorizontalProgramId();
// create the mesh
this.triangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, this.triangleVertices);
GLES20.glEnableVertexAttribArray(positionHandle);
this.triangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
GLES20.glVertexAttribPointer(textureHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, this.triangleVertices);
GLES20.glEnableVertexAttribArray(textureHandle);
Matrix.setIdentityM(this.mvpMatrix, 0);
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, this.mvpMatrix, 0);
GLES20.glUniformMatrix4fv(stMatrixHandle, 1, false, this.stMatrix, 0);
GLES20.glBindTexture(GL_TEXTURE_2D, textureHandle);
GLES20.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, newFbo[0]);
GLES20.glUseProgram(verticalProgramId);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
GLES20.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, newFbo[1]);
GLES20.glBindTexture(GL_TEXTURE_2D, newTex[0]);
GLES20.glUseProgram(horizontalProgramId);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
GLES20.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Re-enable the default window-system framebuffer for drawing
GLES20.glBindTexture(GL_TEXTURE_2D, newTex[0]);
}
I'm trying to create some code for loading and drawing 2D textures in LWJGL. Here is my code for drawing:
glfwShowWindow(window);
GL.createCapabilities();
loadTextures();
glClearColor(1f, 1f, 1f, 1f);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glTranslatef(100, 100, 0);
glBindTexture(GL_TEXTURE_2D, testTexture);
glBegin(GL_QUADS);
{
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(1, 0);
glVertex2f(TEXTURE_WIDTH, 0);
glTexCoord2f(1, 1);
glVertex2f(TEXTURE_WIDTH, TEXTURE_HEIGHT);
glTexCoord2f(0, 1);
glVertex2f(0, TEXTURE_HEIGHT);
}
glEnd();
glPopMatrix();
//end draw
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
glfwTerminate();
glfwSetErrorCallback(null).free();
And this is my texture loading code:
try
{
BufferedImage image = ImageIO.read(file);
/*
if (image.getType() != BufferedImage.TYPE_INT_ARGB)
{
throw new TextureException("Invalid image!");
}
*/
int[] pixels = new int[image.getWidth() * image.getHeight()];
image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
ByteBuffer byteBuffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
for (int x = 0; x < image.getWidth(); x++)
{
for (int y = 0; y < image.getHeight(); y++)
{
int pixel = pixels[y * image.getWidth() + x];
byteBuffer.put((byte)((pixel >> 16) & 0xFF));
byteBuffer.put((byte)((pixel >> 8) & 0xFF));
byteBuffer.put((byte)(pixel & 0xFF));
byteBuffer.put((byte)((pixel >> 24) & 0xFF));
}
}
byteBuffer.flip();
int textureID = glGenTextures();
glBindTexture(GL_TEXTURE_2D, textureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, byteBuffer);
return textureID;
}
catch (Exception e)
{
e.printStackTrace();
throw new TextureException("Failed to load image!");
}
However, when I run this code all I get is a white screen. I checked the value of testTexture and it was set to 1, so I assume that's the texture's ID which makes me believe that worked, but I think there's something going wrong when drawing.
Two-dimensional texturing has to be enabled by glEnable and can be disabled by glDisable:
glEnable(GL_TEXTURE_2D);
If texturing is enables then the texture wich is currently bound is applied, when the geometry is drawn by the glBegin/glEnd sequences.
If you want to draw the geometry in window (pixel) coordinates, then you've to set an orthographic projection with. The orthographic projection can be set by glOrtho.
If you dont set the orthographic projection, the vertex coordinates would have to be in normalized device space in range [-1.0, 1.0].
In the following windowWidth an windowHeight is assumed to be the width and height of the window:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, windowWidth, windowHeight, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// [...]
}
I've got some code that's supposed to render text to a texture so that I don't have to render each character each draw step, and can instead use the rendered texture. However, my code does not as it's supposed to, and the texture is left blank. After a few hours of trying different things, I cannot figure it out, and so I bring the question to you.
I'm fairly certain the problem is somewhere in this code chunk below, but if you think it's not, I'll gladly post whatever other samples of code you would like. I just really want to get this done already. The exact problem is that the created texture is blank, and never is rendered to (it seems like). I've tried just drawing one massive quad on it, and that didn't seem to work either.
Edit: After flipping the buffer, I can get some color to be rendered to the texture, but it's all just one color (which makes me think it's only sampling one pixel), and I can't figure out how to get the actual image I want to render to show on it.
public Text(String text, int x, int y, Font font, float size, GUIComponent parent, Binding binding) {
super(null, x, y, font.getStringWidth(size, text), font.getStringHeight(size), parent, binding, false);
this.text = text;
this.font = font;
this.width = font.getStringWidth(size, text);
this.height = font.getStringHeight(size);
int fbo = glGenFramebuffers();
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
int tex = glGenTextures();
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0);
IntBuffer intBuffer = BufferUtils.createIntBuffer(1);
intBuffer.put(GL_COLOR_ATTACHMENT0);
intBuffer.flip();
glDrawBuffers(intBuffer);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
throw new RuntimeException("Something really bad happened");
}
//RENDER
RenderUtil.recalibrate(width, height, 1.0f); //Does glViewport(width, height), and some matrix stuff
Camera.updateShader("textshader", "projection", false); //Update projection matrix
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
int width = 0;
float f = this.width / 1.0f;
int charWidth = 0;
for (char c : text.toCharArray()) {
font.bind(0, c % 256); // calls glBindTexture, this works, have tested
//ResourceManager.getTexture("grassroadedger1").bind(0, 0);
charWidth = font.getCharWidth(size, c);
//float[] verts = new float[] { -1f, 1f, 1f, 1f, 1f, -1f, -1f, -1f };
float[] verts = new float[] { -1.0f + (width / f), 1.0f, 1.0f + ((width + charWidth) / f), 1.0f, 1.0f + ((width + charWidth) / f), -1.0f, -1.0f + (width / f), -1.0f };
width += charWidth;
glBindBuffer(GL_ARRAY_BUFFER, vertexPointer);
glBufferSubData(GL_ARRAY_BUFFER, 0, RenderUtil.createBuffer(verts));
glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, RenderUtil.getIndicesPointer());
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
//END
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
RenderUtil.recalibrate(Window.getWidth(), Window.getHeight(), LuminaEngine.getGlobalImageScale());
this.setTexture(new Texture(tex, "text_"+size+"_"+text));
}
FragmentShader
#version 330 core
in vec2 uv;
layout(location = 0) out vec4 color;
uniform sampler2D sampler;
void main(){
color = texture2D( sampler, uv );
}
Vertex Shader
#version 330 core
layout(location = 0) in vec3 vertices;
layout(location = 1) in vec2 textures;
out vec2 uv;
uniform mat4 projection;
void main(){
gl_Position = projection * vec4(vertices,1);
uv = textures;
}
Edit: After flipping the intBuffer for drawBuffers, I can get some things to appear, mostly just a big blue square. Progress nonetheless
You never defined an array of generic vertex attribute data for the texture coordinates (in vec2 textures;).
Add something like this to your code:
int texCoordBuffer;
glGenBuffers(1, texCoordBuffer);
float[] texCoord = new float[] { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f };
glBindBuffer(GL_ARRAY_BUFFER, texCoordBuffer);
glBufferData(GL_ARRAY_BUFFER, RenderUtil.createBuffer(texCoord), GL_STATIC_DRAW);
int tax_attr_i = 1; // layout(location = 1) in vec2 textures;
glVertexAttribPointer(tax_attr_i, 2, GL_FLOAT, false, 0, 0);
The preview from my camera is rendered to a texture. I have the textureId and am trying to render the texture on a FBO so I can glReadPixels.
When I do actually read the pixels, all of them appear to be black though.
This is the code I am using at the moment:
//called when the camera first connects to the texture
public void initBackBuffer()
{
// For use in getFramePixels()
intBuffer = ByteBuffer.allocateDirect(width *
height * 4)
.order(ByteOrder.nativeOrder())
.asIntBuffer();
IntBuffer framebuffer = IntBuffer.allocate(1);
glGenFramebuffers(1, framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get(0));
int status = glGetError();
if(status != GL_NO_ERROR)
{
Log.e("RENDERER", status + "");
}
IntBuffer depthBufferName = IntBuffer.allocate(1);
glGenRenderbuffers(1, depthBufferName);
glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName.get(0));
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
depthBufferName.get(0));
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
mTangoCameraTexture.getTextureId(), 0);
mOffscreenBuffer = framebuffer.get(0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE) {
if(status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
Log.e("RENDERER","GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT");
if(status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
Log.e("RENDERER", "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");
Log.e("RENDERER", "FRAMEBUFFER ERROR:"+status);
}
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
}
// called onFrameAvailable
public void getFramePixels() {
glBindFramebuffer(GL_FRAMEBUFFER, mOffscreenBuffer);
int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
Log.e(TAG, "FRAMEBUFFER STATUS:"+status);
}
glReadPixels(0, 0, width, height, GL_RGBA,
GL_UNSIGNED_BYTE,
intBuffer.clear());
StringBuilder str = new StringBuilder();
for(int i = 0; i < intBuffer.capacity(); i++)
{
str.append(intBuffer.get(););
}
Log.d(TAG, "IMAGE:" + str.toString());
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
If I display the texture on the screen, I am able to see it - so the texture not being actually bound to the camera is excluded.
Edit: there's a GL_INVALID_OPERATION happening at glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D, getTextureId(), 0); for some reason.
From the docs:
GL_INVALID_OPERATION is generated if zero is bound to target.
GL_INVALID_OPERATION is generated if textarget and texture are not compatible.
My textureId is 1.
Read the docs more carefully. Your texture ID may be 1, but what you have currently bound to the target is likely actually 0. If you don't call glBindTexture(GL_TEXTURE_2D, mTangoCameraTexture.getTextureId()); then GL_TEXTURE_2D (the target) is whatever you set it to last, which I'm inclined to say is probably 0.
If you find you have performance issues surrounding glReadPixels() you should consider using it alongside a Pixel Buffer Object.
This is the content of my Texture class:
public int id;
public Texture(InputStream inputStream) {
ByteBuffer buf = null;
int tWidth = 0;
int tHeight = 0;
try {
PNGDecoder decoder = new PNGDecoder(inputStream);
buf = ByteBuffer.allocateDirect(4*decoder.getWidth()*decoder.getHeight());
decoder.decode(buf, decoder.getWidth()*4, PNGDecoder.TextureFormat.RGBA);
buf.rewind();
inputStream.close();
} catch (IOException exception) {
ErrorHandler.handleError("Failed to load image", exception);
}
id = glGenTextures();
glActiveTexture(id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
glBindTexture(GL_TEXTURE_2D, 0);
}
This is how i render:
glActiveTexture(background.id);
glBindTexture(GL_TEXTURE_2D, background.id);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 4*18);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glBindTexture(GL_TEXTURE_2D, 0);
and this is the fragment shader:
#version 330
in vec2 textureCoordinate;
out vec4 outputColor;
uniform sampler2D texture_diffuse;
void main() {
outputColor.rgb = vec3(1.0f, 1.0f, 1.0f);
outputColor += texture2D(texture_diffuse, textureCoordinate);
}
What do i do wrong? The texture coordinates passed to the shader program are 100% correct (i checked). But i still get a white quad.
Note: i use this png decoder.
EDIT:
I printed out floats for every 4 bytes to the console, and i got 0.00.00.00.0.... Doest that mean that the texture is loaded incorectly, or the informations is stored to the buffer in a different format?
Your fragment shader looks wrong - you set a white colour and add the value from the texture, so it will clamp to white. Just do something more like this
void main() {
outputColor.a = 1.0f;
outputColor.rgb = texture2D(texture_diffuse, textureCoordinate);
}