opengl - OpenTK - After multiplying with ProjectionMatrix nothing is rendering anymore -


from tutorial refused explain got following code. lwjgl tutorial copied worked fine. i'm not sure if problem created having opengl differ java opengl, since it's math surprised that:

private void createprojectionmatrix(int width, int height) {     float aspectratio = width / height;     float yscale = (float)((1f / math.tan(maths.degreetoradian(fov/2f))) * aspectratio);     float xscale = yscale / aspectratio;     float frustumlength = far_plane - near_plane;      projectionmatrix = new matrix4();     projectionmatrix.m11 = xscale;     projectionmatrix.m22 = yscale;     projectionmatrix.m33 = -((far_plane + near_plane) / frustumlength);     projectionmatrix.m34 = -1;     projectionmatrix.m43 = -((2 * near_plane * far_plane) / frustumlength);     projectionmatrix.m44 = 0;    } 

this multiplied transformation matrix (which worked). matrix shader doing uniformlocation_projectionmatrix = gl.getuniformlocation(programid, "projectionmatrix") followed gl.uniformmatrix4(uniformlocation_projectionmatrix, false, ref projectionmatrix) way got transformationmatrix in there too, shouldn't problem.
in shader gl_position = projectionmatrix * transformationmatrix * vec4(in_position, 1.0) (again, without projectionmatrix works fine), , before uniform mat4 projectionmatrix; (as can confirm spelled same).
i'm not sure further part of code need, feel free ask, thank you.
edit 1: tried transposing (by setting false true), resut same

edit 2:
matrix created code above:
(1,428148; 0; 0; 0) ( 0; 2,53893; 0; 0) ( 0; 0; -1,002002; -1) ( 0; 0; -0,2002002; 0)

the matrix created matrix4.createperspectivefieldofview():
(0,8033332; 0; 0; 0) ( 0; 1,428148; 0; 0) ( 0; 0; -1,002002; -1) ( 0; 0; -0,2002002; 0)
matrix created layout draykoon d's answer:
(-0,00015625; 0; 0; 0) ( 0; 0,0002777778; 0; 0) ( 0; 0; -1,002002; -0,2002002) ( 0; 0; -1; 0)

i convinced problem lies elsewere - 3 matricies don't work.

edit 3 - more code: vertexshader far

#version 440 core  layout (location = 0) in vec3 in_position; layout (location = 1) in vec2 in_texturecoordinates;  uniform mat4 translation; uniform mat4 rotationx; uniform mat4 rotationy; uniform mat4 rotationz; uniform mat4 scale;  uniform mat4 projectionmatrix;  out vec2 texturecoordinates;  void main(void) {     mat4 transformationmatrix = translation * rotationx * rotationy * rotationz * scale;     gl_position = projectionmatrix * transformationmatrix * vec4(in_position,  1.0);     texturecoordinates = in_texturecoordinates; } 

and render function:

public void render(entity entity, shaderprogram shader)     {         texturedmodel texturedmodel = entity.model;         rawmodel model = texturedmodel.model;         gl.bindvertexarray(model.vaoid);         gl.enablevertexattribarray(0);         gl.enablevertexattribarray(1);         shader.loadtransformationmatrix(             entity.position, entity.rotx, entity.roty, entity.rotz, entity.scale);         gl.activetexture(textureunit.texture0);         gl.bindtexture(texturetarget.texture2d, texturedmodel.texture.id);         gl.drawelements(beginmode.triangles, model.vertexcount, drawelementstype.unsignedint, 0);         gl.disablevertexattribarray(0);         gl.disablevertexattribarray(1);         gl.bindvertexarray(0);     }     

and constructor of renderer loads projectionmatrix:

public renderer(int width, int height, shaderprogram shader)     {         createprojectionmatrix(width, height);         shader.loadprojectionmatrix(projectionmatrix);     } 

if want try other method of building projection matrix, can try 1 th math explanation

enter image description here

should not hard,

r , l stand right , left , should -width/2, width2

b , t stand bottom , right, -height/2, height/2

n , f stand near , far plane try different values, check z belongs interval, luck. not sure on scheme see sign of near , far plane.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -