first attempt to bind texture
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "BlockRenderer.h"
|
||||
#include "../gl/Texture.h"
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
@ -11,15 +12,15 @@
|
||||
VertexArray *BlockRenderer::setVertexArray() {
|
||||
float cube_vertices[] = {
|
||||
// front
|
||||
-1.0, -1.0, 1.0,
|
||||
1.0, -1.0, 1.0,
|
||||
1.0, 1.0, 1.0,
|
||||
-1.0, 1.0, 1.0,
|
||||
-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,
|
||||
1.0, -1.0, -1.0,
|
||||
1.0, 1.0, -1.0,
|
||||
-1.0, 1.0, -1.0
|
||||
-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,
|
||||
};
|
||||
|
||||
GLfloat cube_colors[] = {
|
||||
@ -83,6 +84,12 @@ Shader BlockRenderer::setShader() {
|
||||
Shader s;
|
||||
s.loadShader(vertsrc, geosrc, fragsrc);
|
||||
s.Bind();
|
||||
|
||||
Texture t;
|
||||
t.Bind();
|
||||
glUniform1i(s.getUniformHandle("u_texture"), 0);
|
||||
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
R"(#version 330 core
|
||||
out vec4 color;
|
||||
uniform vec3 u_color;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
in vec3 normal;
|
||||
in vec4 pos;
|
||||
in vec2 v_texcoords;
|
||||
|
||||
void main()
|
||||
{
|
||||
@ -15,6 +17,9 @@ void main()
|
||||
// set light color
|
||||
vec3 diffuse = diff * vec3(1.0,1.0,1.0);
|
||||
|
||||
vec3 result = (diffuse) * u_color;
|
||||
color = vec4(result,0.0);
|
||||
vec4 c = texture(u_texture, v_texcoords);
|
||||
|
||||
vec3 result = (diffuse) * c.xyz;
|
||||
// color = vec4(result,0.0);
|
||||
color = c;
|
||||
})";
|
@ -4,7 +4,6 @@ layout(triangles) in;
|
||||
layout(triangle_strip, max_vertices=3) out;
|
||||
|
||||
out vec3 normal;
|
||||
|
||||
out vec4 pos;
|
||||
|
||||
void main( void )
|
||||
|
@ -1,16 +1,17 @@
|
||||
R"(#version 330 core
|
||||
// Input vertex data, different for all executions of this shader.
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 texCoords;
|
||||
|
||||
//// Values that stay constant for the whole mesh.
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 translation;
|
||||
|
||||
out vec3 FragPos;
|
||||
out vec2 v_texcoords;
|
||||
|
||||
void main(){
|
||||
// Output position of the vertex, in clip space : MVP * position
|
||||
vec4 pos = MVP * translation * vec4(vertexPosition_modelspace,1);
|
||||
gl_Position = pos;
|
||||
FragPos = pos.xyz;
|
||||
v_texcoords = texCoords;
|
||||
})";
|
Reference in New Issue
Block a user