fix texture rendering
This commit is contained in:
@ -10,40 +10,101 @@
|
||||
#include <GL/gl.h>
|
||||
|
||||
VertexArray *BlockRenderer::setVertexArray() {
|
||||
// float cube_vertices[] = {
|
||||
// // front
|
||||
// -1.0, -1.0, 1.0, 0.0f, 0.0f,
|
||||
// 1.0, -1.0, 1.0, 1.0f, 0.0f,
|
||||
// 1.0, 1.0, 1.0, 0.0f, 1.0f,
|
||||
// -1.0, 1.0, 1.0, 1.0f, 1.0f,
|
||||
// // back
|
||||
// -1.0, -1.0, -1.0, 0.0f, 0.0f,
|
||||
// 1.0, -1.0, -1.0, 1.0f, 0.0f,
|
||||
// 1.0, 1.0, -1.0, 0.0f, 1.0f,
|
||||
// -1.0, 1.0, -1.0, 1.0f, 1.0f,
|
||||
// };
|
||||
|
||||
float cube_vertices[] = {
|
||||
// front
|
||||
-1.0, -1.0, 1.0, 0.0f, 0.0f,
|
||||
1.0, -1.0, 1.0, 1.0f, 0.0f,
|
||||
1.0, 1.0, 1.0, 0.0f, 1.0f,
|
||||
-1.0, 1.0, 1.0, 1.0f, 1.0f,
|
||||
-1, -1, 1, 0, 0,
|
||||
1, -1, 1, 1, 0,
|
||||
1, 1, 1, 0, 1,
|
||||
-1, 1, 1, 1, 1,
|
||||
// back
|
||||
-1.0, -1.0, -1.0, 0.0f, 0.0f,
|
||||
1.0, -1.0, -1.0, 1.0f, 0.0f,
|
||||
1.0, 1.0, -1.0, 0.0f, 1.0f,
|
||||
-1.0, 1.0, -1.0, 1.0f, 1.0f,
|
||||
-1, -1, -1, 0, 0,
|
||||
1, -1, -1, 1, 0,
|
||||
1, 1, -1, 0, 1,
|
||||
-1, 1, -1, 1, 1,
|
||||
};
|
||||
|
||||
GLfloat cube_colors[] = {
|
||||
// front colors
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
// back colors
|
||||
1.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 1.0,
|
||||
1.0, 1.0, 1.0
|
||||
};
|
||||
float cubee[] = {
|
||||
// face #1
|
||||
1, 1, 1, 1, 0,
|
||||
-1, 1, 1, 1, 1,
|
||||
-1, -1, 1, 0, 1,
|
||||
1, -1, 1, 0, 0,
|
||||
|
||||
// face #2
|
||||
1, 1, 1, 1, 0,
|
||||
1, -1, 1, 1, 1,
|
||||
1, -1, -1, 0, 1,
|
||||
1, 1, -1, 0, 0,
|
||||
|
||||
// face #3
|
||||
1, 1, 1, 1, 0,
|
||||
1, 1, -1, 1, 1,
|
||||
-1, 1, -1, 0, 1,
|
||||
-1, 1, 1, 0, 0,
|
||||
|
||||
// face #4
|
||||
-1, -1, -1, 1, 0,
|
||||
-1, 1, -1, 1, 1,
|
||||
1, 1, -1, 0, 1,
|
||||
1, -1, -1, 0, 0,
|
||||
|
||||
// face #5
|
||||
-1, -1, -1, 1, 0,
|
||||
-1, -1, 1, 1, 1,
|
||||
-1, 1, 1, 0, 1,
|
||||
-1, 1, -1, 0, 0,
|
||||
|
||||
// face #6
|
||||
-1, -1, -1, 1, 0,
|
||||
1, -1, -1, 1, 1,
|
||||
1, -1, 1, 0, 1,
|
||||
-1, -1, 1, 0, 0,};
|
||||
|
||||
// Generate a vertex buffer
|
||||
auto *vb = new VertexBuffer(cube_vertices, sizeof(cube_vertices));
|
||||
|
||||
//
|
||||
auto *vb = new VertexBuffer(cubee, sizeof(cubee));
|
||||
return new VertexArray(*vb);
|
||||
}
|
||||
|
||||
IndexBuffer *BlockRenderer::setIndexBuffer() {
|
||||
unsigned indexx[] = {
|
||||
0, 1, 2,
|
||||
2, 3, 0,
|
||||
|
||||
4, 5, 6,
|
||||
6, 7, 4,
|
||||
|
||||
8, 9, 10,
|
||||
10, 11, 8,
|
||||
|
||||
12, 13, 14,
|
||||
14, 15, 12,
|
||||
|
||||
16, 17, 18,
|
||||
18, 19, 16,
|
||||
|
||||
20, 21, 22,
|
||||
22, 23, 20,
|
||||
|
||||
24, 25, 26,
|
||||
26, 27, 24,
|
||||
|
||||
28, 29, 30,
|
||||
30, 31, 28
|
||||
};
|
||||
|
||||
unsigned cube_elements[] = {
|
||||
// front
|
||||
0, 1, 2,
|
||||
@ -65,7 +126,7 @@ IndexBuffer *BlockRenderer::setIndexBuffer() {
|
||||
6, 7, 3
|
||||
};
|
||||
|
||||
return new IndexBuffer(cube_elements, 36);;
|
||||
return new IndexBuffer(indexx, 48);
|
||||
}
|
||||
|
||||
Shader BlockRenderer::setShader() {
|
||||
|
@ -5,7 +5,7 @@ uniform sampler2D u_texture;
|
||||
|
||||
in vec3 normal;
|
||||
in vec4 pos;
|
||||
in vec2 v_texcoords;
|
||||
in vec2 texcoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -17,9 +17,9 @@ void main()
|
||||
// set light color
|
||||
vec3 diffuse = diff * vec3(1.0,1.0,1.0);
|
||||
|
||||
vec4 c = texture(u_texture, v_texcoords);
|
||||
vec4 c = texture(u_texture, texcoords);
|
||||
|
||||
vec3 result = (diffuse) * c.xyz;
|
||||
// color = vec4(result,0.0);
|
||||
color = c;
|
||||
color = vec4(result,0.0);
|
||||
// color = c;
|
||||
})";
|
@ -6,6 +6,9 @@ layout(triangle_strip, max_vertices=3) out;
|
||||
out vec3 normal;
|
||||
out vec4 pos;
|
||||
|
||||
in vec2 v_texcoords[];
|
||||
out vec2 texcoords;
|
||||
|
||||
void main( void )
|
||||
{
|
||||
vec3 a = ( gl_in[1].gl_Position - gl_in[0].gl_Position ).xyz;
|
||||
@ -17,6 +20,7 @@ void main( void )
|
||||
gl_Position = gl_in[i].gl_Position;
|
||||
normal = N;
|
||||
pos = gl_in[i].gl_Position;
|
||||
texcoords = v_texcoords[i];
|
||||
EmitVertex( );
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user