Hello Guest

Recent Posts

Pages: 1 ... 7 8 [9] 10
81
OpenGL / Re: I'm unable to properly blend z-ordered textures
« Last post by KaiHH on November 16, 2020, 10:41:49 »
Depth testing happens before alpha blending, so all fragments of the later drawn object behind the front object are discarded.
When you want to draw transparent objects, you must sort/draw them from back/furthest to front/nearest.
82
OpenGL / I'm unable to properly blend z-ordered textures
« Last post by noncompetitive_antagonist on November 16, 2020, 00:02:59 »
Hi there,

I am not able to implement transparency blending properly when I have one object being drawn *after* another object, and *beneath* that other object. See here:
https://imgur.com/ccmg0IT
In this picture, the upper-left image is being rendered first, and the lower-right image is being rendered second. The upper-left image has a lower z index, so it is higher than the lower-right image; this is correct. However, its transparency "overwrites" the non-transparency of the lower-right image beneath it. I am currently using the following code for my blending function and equation:

Code: [Select]
        glEnable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glBlendEquation(GL_FUNC_ADD);

Am I missing something obvious? (I've double-checked that I'm not setting a different blend function elsewhere, for instance.)

Thanks!
83
I figured out the problem--I was disabling depth testing elsewhere in my code.  :-[
84
OpenGL / LookAt matrix and model matrix transpose
« Last post by Mihai_Ionut_Floares on November 15, 2020, 19:31:14 »
Hi I encounter a weird thing:
I have a transformation matrix like this(since I want only to translate this will serve as model matrix too):

I have it as a float:

I have one stored as a float[][] in java that moves by 0.5 on every axis:
1 0 0 0.5
0 1 0 0.5
0 0 1 0.5
0 0 0 1

when I send it to glsl as a float[] I construct the float transposed like this:
1 0 0 0 0 1 0 0 0 0 1 0.5 0.5 0.5 1(first column represents the first 4 elements from array)

It works when I send it as a float[] like this

The view matrix:


I construct it like this and the final matrix is:
1.0 0.0 0.0 -4.0
0.0 1.0 0.0 -3.0
0.0 0.0 1.0 -3.0
0.0 0.0 0.0 1.0
(camera at 4 3 3, looking at 0 0 0 and up is at 0 1 0)

When I transpose it(first column represents the first elements of float[]) it isn't working. When I don't transpose it is working and I don't know why

The prjection matrix


I setup and the final mat is:
1.7320509 0.0 0.0 0.0
0.0 1.7320509 0.0 0.0
0.0 0.0 -1.002002 -0.2002002
0.0 0.0 -1.0 0.0

This isn't working even if I transpose it and I don't know why.
Please look at this screen capture and help me with setting up the matrices:
https://streamable.com/2o1m9t

85
Bug Reports / RFE / Re: [BUG] framebuffer size of a mac
« Last post by jakethesnake on November 15, 2020, 15:39:10 »
Calm down everyone, don't answer all at the same time   8)

After a new mac user had new troubles after a os update, I did some more testing and desperate attempts.

With some further testing, I also noticed that the window size that is half of my retina maximum resolution works perfectly. 2305x1296 creates a FB that's 4608x2592. The bigger and smaller screen resolutions reported by glfGetVideoModes also creates twice the size FB, but they simply don't fit in the window. It's like 2308x1296 is "retina compatible", while the other ones aren't, but still GLFW tells me the framebugger is twice the size of those windows.

Meanwhile, opengl tells me the framebuffer is 4608x2592 on all chosen resolutions except 2304x1296 when I poll scissor and viewport size at init.
86
Hello! I'm trying to render textures at different z indices, by assigning values through my shaders. I've tested that I am able to successfully set my uniform values prior to running my shader program. Here is my attempt at setting the z-index in my vertex shader:

Code: [Select]
#version 140

in vec2 position;
in vec2 textureCoords;

out vec4 color;
out vec2 uvCoords;

uniform float zIndex;
uniform vec4 matColor;
uniform mat4 projection;
uniform vec4 offset;
uniform vec2 pixelScale;
uniform vec2 screenPosition;

void main()
{
    color = matColor;
    gl_Position = projection * vec4((position * pixelScale) + screenPosition, 0, 1);
    gl_Position.z = zIndex;
    uvCoords = (textureCoords * offset.zw) + offset.xy;
}

I am fairly certain that this is indeed setting the z-index properly, since if I set it to an out-of-bounds value (e.g. 1.01f), it causes textures rendered at that value to disappear. This, and some google searches, makes me think that I'm missing some way of enabling depth-testing... Here is the code I'm using to (try to) enable depth testing:

Code: [Select]
        glEnable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_ALPHA_TEST);
        glDepthFunc(GL_LESS);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I've tried disabling GL_BLEND, as some search results suggested, but this has not done the trick. What am I missing here?

Thanks!
87
OpenGL / How does GLSL read a matrix?
« Last post by Mihai_Ionut_Floares on November 13, 2020, 21:56:26 »
Let's say I have a projection matrix:


GLSL thinks -(2*Zfar*Znear)/zm is at position in matrix 2x3 or at 3x2?
Should I set in my float[][](2D array)
Code: [Select]
projectionMatrix.mat[2][3] =  -(2*Zfar*Znear)/zm;

or

Code: [Select]
projectionMatrix.mat[3][2] =  -(2*Zfar*Znear)/zm;

???
88
OpenGL / Re: Send 2d array to uniform mat4 matrix
« Last post by Mihai_Ionut_Floares on November 13, 2020, 20:50:07 »
I succeed I need to convert the 2D position/rotation/scale/projection array(float[][]) into a 1D float array(float[])
Ex(I have this scale matrix as a float[][]):
2 0 0 0
0 2 0 0
0 0 2 0
0 0 0 1

I needed to put in a float[] like that:
2 0 0 0 0 2 0 0 0 0 2 0 0 0 0 1

and then send the float[] directly to GLSL without any float buffer like that:
Code: [Select]
glUseProgram(programID);
int MatrixID = glGetUniformLocation(programID, "theMatrix");
glUniformMatrix4fv(MatrixID, false, translationArray);

glUseProgram(0);
89
OpenGL / Send 2d array to uniform mat4 matrix
« Last post by Mihai_Ionut_Floares on November 12, 2020, 19:14:26 »
Hi, I posted a similar question but I get no answer so I simplify it in this forum. Please do not mark as duplicate. If I have a 2d float array like (float[][] transformMatrix = new float[][]) I want to send it to the shader to be used with the inPosition:
Code: [Select]
void main()
    {

        gl_Position = transformation * in_Position;
    }

I tried like this:
Code: [Select]
glUseProgram(programID);


for(int i = 0; i < 4;i++) {
for(int j = 0;j<4;j++) {
matrix44Buffer.put(transformation.mat[i][j]);
}
}
glUniformMatrix4fv(MatrixLocation, false, matrix44Buffer);

       


matrix44Buffer.flip();

       
         
        glUseProgram(0);

It isn't working. How to send the float[][] to the shader? All the websites that I found were using JOML or lwjgl 2 which has its own matrices.
90
OpenGL / Send the matrix to shader in java(model * view * projection)
« Last post by Mihai_Ionut_Floares on November 11, 2020, 20:59:49 »
If i built my own matrix and vector classes and I have the model matrix, the view matrix and the projection matrix as 2d arrays and I multiply them with with:
Code: [Select]
for(int n = 0;n<4;n++) {
for(int i = 0;i<4;i++) {
for(int j = 0;j<4;j++) {
result.mat[i][n] += mat1.mat[i][j] * mat2.mat[j][n];
}
}
}

I get a mat4 class(the matrix class). The array is located in the class:
Code: [Select]
mat4x4.mat(the mat is the array name and the mat4x4 is a new mat4 class/object)


and at final after multiplying, I need to send it to the vertex shader and I tried like this:
Code: [Select]
//init
mat4 MVP = new mat4();

//MVP = the multiplication of model, view and projection matrice
int MatrixID = glGetUniformLocation(programID, "MVP");
//the main loop
FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(16);// IDK why 16
glUniformMatrix4fv(MatrixID, true, floatBuffer);


This doesn't work, the triangle is on the entire screen like before, seen as 2d and now the OpenGL ignores the fragment shader. In the frag shader I told it to draw the triangle blue and it was blue, but fter I tried to send the matrix to the vertex shader like above, the trangle is white, so it isn't compiling the fragment shader. 
The question is how to send the final MVP matrix to the shader, because I don't think GLSL knows about my mat4 class. Should I send only the array component(mat4x4.mat  where mat4 mat4x4 = new mat4()), or what shoud I send to GLSL and how to deal with the floatBuffer parameter. I couldn't find on google anything about that.

The SimpleVertexShader.vertexshader:
Code: [Select]
#version 330 core
layout(location = 0) in vec3 vertexPosition_modelspace;
uniform mat4 MVP;
void main(){
  gl_Position =  MVP * vec4(vertexPosition_modelspace,1);
  transformed_vertex = MVP * in_vertex;
}

Pages: 1 ... 7 8 [9] 10