kolijk Temat założony przez niniejszego użytkownika |
Nauka programowania w OpenGL. » 2017-11-14 14:07:09 Witam zaczynam się uczyć programowania w OpenGL i czy ktoś zna jakieś dobre poradniki do OpenGL? (najlepiej w kierunku gier 3D).
I jeszcze czy tworząc gry w OpenGL warto obeznać się z biblioteką SDL? |
|
slowbro |
» 2017-11-14 21:20:56 http://www.opengl-tutorial.org/ https://learnopengl.com/
SDL nie jest potrzebny |
|
czaffik |
» 2017-11-24 19:36:13 Do opengl możesz używać różnych bibliotek, glut, sfml, sdl, qt, jednak używanie z sdlem może być problematyczne, często pojawiały mi się dziwne błędy związane z shaderami (uniformy nie chciały się poprawnie przesyłać, geometry shader który teoretycznie powinien działać wywalał błąd), może to wina mingw, na początku zmieniałem plik glext.h i coś pomogło, ale jednak nie do końca. Qt ma lepiej dopracowany interfejs do opengla. |
|
Gabes |
» 2017-11-25 08:19:34 ta, glext..., MinGW.., twój laptop, był nie teges:) |
|
czaffik |
» 2017-11-25 21:10:30 Ups, pomyłka, a jednak na dobre wyszło, działa: #version 450 precision highp int; precision highp float;
layout( location = 0 ) in vec3 position; layout( location = 1 ) in vec2 texcoord; layout( location = 2 ) in vec3 normal; layout( location = 3 ) in vec3 tangent;
out VertexData { vec2 texcoord; vec3 eye; vec4 lightDir[ 10 ]; } vertex;
layout( std140, binding = 0 ) uniform CameraBlock { mat4 proj; mat4 view; vec4 viewPos; };
layout( std140, binding = 1 ) uniform LightsBlock { vec4 light_ambient; vec4 light_pos[ 10 ]; vec4 light_attr[ 10 ]; };
uniform mat4 model; uniform float scale;
void main() { mat4 scaleMat = mat4( scale, 0.0, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, 0.0, scale, 0.0, 0.0, 0.0, 0.0, 1.0 ); mat4 vMat = proj * view * model * scaleMat; mat4 viewModel = view * model * scaleMat; mat4 timodel = transpose( inverse( model * scaleMat ) ); vec3 n = normalize( vec3( timodel * vec4( normal, 1.0 ) ) ); vec3 t = normalize( vec3( timodel * vec4( tangent, 1.0 ) ) ); vec3 b = normalize( cross( t, n ) ); mat3 TBN = transpose( mat3( t, b, n ) ); vec3 pos = vec3( model * scaleMat * vec4( position, 1.0 ) ); vertex.texcoord = texcoord; vertex.eye = normalize( TBN *( viewPos.xyz - pos ) ); int lightsCount = int( light_ambient.a ); for( int i = 0; i < lightsCount; i++ ) { vec3 diff = light_pos[ i ].xyz - pos; vertex.lightDir[ i ] = vec4( normalize( TBN * diff ), length( diff ) ); } gl_Position = vMat * vec4( position, 1.0 ); }
#version 450
layout( triangles ) in; layout( triangle_strip, max_vertices = 12 ) out;
in VertexData { vec2 texcoord; vec3 eye; vec4 lightDir[ 10 ]; } vertex[];
out FragData { vec2 texcoord; vec3 eye; vec4 lightDir[ 10 ]; } frag;
void main() { for( int i = 0; i < gl_in.length(); i++ ) { gl_Position = gl_in[ i ].gl_Position; frag.texcoord = vertex[ i ].texcoord; frag.eye = vertex[ i ].eye; for( int k = 0; k < 10; k++ ) frag.lightDir[ k ] = vertex[ i ].lightDir[ k ]; EmitVertex(); } EndPrimitive(); }
#version 450 precision highp int; precision highp float;
out vec4 outColor;
struct Material { vec4 ambient; vec4 diffuse; vec4 specular; vec4 emission; vec2 overlap; float shininess; };
in FragData { vec2 texcoord; vec3 eye; vec4 lightDir[ 10 ]; } frag;
layout( std140, binding = 1 ) uniform LightsBlock { vec4 light_ambient; vec4 light_pos[ 10 ]; vec4 light_attr[ 10 ]; };
uniform sampler2D tex0; uniform sampler2D tex1; uniform Material material;
void main() { vec2 uv = vec2( frag.texcoord.x * material.overlap.x, frag.texcoord.y * material.overlap.y ); vec4 col = texture( tex0, uv ); vec3 normal = normalize( 2.0 * texture( tex1, uv ).rgb - 1.0 ); vec4 ambientColor = material.ambient * vec4( light_ambient.rgb, 1.0 ); vec4 emissionColor = material.emission; vec4 lightsColor = vec4( 0.0, 0.0, 0.0, 1.0 ); int lightsCount = int( light_ambient.a ); for( int i = 0; i < lightsCount; i++ ) { float value = max( dot( normal, frag.lightDir[ i ].xyz ), 0.0 ); if( value > 0.0 ) { vec4 diffuseColor = value * material.diffuse * vec4( light_attr[ i ].rgb, 1.0 ); vec3 halfDir = normalize( frag.lightDir[ i ].xyz + frag.eye ); vec4 specularColor = pow( max( dot( normal, halfDir ), 0.0 ), material.shininess ) * material.specular * vec4( light_attr[ i ].rgb, 1.0 ); float att = 1.0; float r = frag.lightDir[ i ].w; if( r != 0.0 && light_attr[ i ].w != 0 ) att = 0.07957747154595 /( light_attr[ i ].w * r * r ); lightsColor += att * max( diffuseColor, specularColor ); } } outColor =( ambientColor + lightsColor ) * col + emissionColor; }
Jednak trochę denerwuje błąd GL_INVALID_ENUM tylko dlatego że dopisało się dwie linijki, może być literówka albo inny głupi błąd, ale takie coś powinno wychwycić glGetShaderInfoLog. |
|
« 1 » |