Simply Not Rendering

Started by CJ Burkey, May 20, 2017, 14:06:52

Previous topic - Next topic

CJ Burkey

I don't know if this is something on my end, but I've Googled this issue for two days now and tried various solutions, none of which worked. The issue is that I cannot get even a simple triangle to render. I have shaders set up and all that fun stuff. The entire project is on https://github.com/cjburkey01/Angulus, but here's the shader and render classes:

Vertex Shader:
#version 330

layout(location = 0) in vec3 position;

void main() {
	gl_Position = vec4(position, 1.0);
}


Fragment Shader:
#version 330

out vec4 fragColor;
void main() {
	fragColor = vec4(1.0, 1.0, 1.0, 1.0);
}


Shader Loader:
private int program;
	
	public Shader() {
		program = GL20.glCreateProgram();
		if(program == 0) {
			Angulus.instance.getLogger().log("Couldn't create shader program.");
			Angulus.instance.kill();
			return;
		}
	}
	
	public abstract void bindAttributes();
	
	protected void bindAttribute(int attrib, String varName) {
		GL20.glBindAttribLocation(program, attrib, varName);
		Angulus.instance.getLogger().log("Bound attrib: " + varName);
	}
	
	public void bind() {
		GL20.glUseProgram(program);
	}
	
	public static void unbind() {
		GL20.glUseProgram(0);
	}
	
	protected void addVertShader(String txt) {
		addProgram(txt, GL20.GL_VERTEX_SHADER);
	}
	
	protected void addFragShader(String txt) {
		addProgram(txt, GL20.GL_FRAGMENT_SHADER);
	}
	
	protected void compileProgram() {
		GL20.glLinkProgram(program);
		if(GL20.glGetProgrami(program, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
			Angulus.instance.getLogger().log("Couldn't link shader program.");
			Angulus.instance.kill();
			return;
		}
		/*GL20.glValidateProgram(program);
		if(GL20.glGetProgrami(program, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) {
			Angulus.instance.getLogger().log("Couldn't validate shader program.");
			Angulus.instance.getLogger().log(GL20.glGetProgramInfoLog(program, 1024));
			Angulus.instance.kill();
			return;
		}*/
		
		bindAttributes();
	}
	
	private void addProgram(String txt, int type) {
		int shader = GL20.glCreateShader(type);
		if(shader == 0) {
			Angulus.instance.getLogger().log("Couldn't create shader.");
			Angulus.instance.kill();
			return;
		}
		GL20.glShaderSource(shader, txt);
		GL20.glCompileShader(shader);
		if(GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == 0) {
			Angulus.instance.getLogger().log("Couldn't compile shader:");
			Angulus.instance.getLogger().log("  " + GL20.glGetShaderInfoLog(shader, 1024));
			Angulus.instance.kill();
			return;
		}
		GL20.glAttachShader(program, shader);
	}
	
	public static String loadShader(String fName) {
		StringBuilder src = new StringBuilder();
		try {
			BufferedReader r = new BufferedReader(new InputStreamReader(Shader.class.getResourceAsStream("/res/shader/" + fName)));
			String l = "";
			while((l = r.readLine()) != null) {
				src.append(l);
				src.append("\n");
			}
			r.close();
		} catch(Exception e) {
			e.printStackTrace();
		}
		return src.toString();
	}


Renderer:
private BasicShader shader;
	private Model m;
	
	public Renderer() {
		init();
		shader = new BasicShader();
		m = new Model();
		Vertex[] v = {
			new Vertex(-1, -1, 0),
			new Vertex(1, -1, 0),
			new Vertex(0, 1, 0),
		};
		m.bufferVertices(v);
	}
	
	public void render() {
		prepare();
		
		shader.bind();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, m.getVbo());
		GL20.glEnableVertexAttribArray(0);
		GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, Vertex.SIZE * 4, 0);
		GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, m.getSize());
		GL20.glDisableVertexAttribArray(0);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		Shader.unbind();
	}
	
	public void cleanup() {
		
	}
	
	private void prepare() {
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	}
	
	private void init() {
		GL11.glEnable(GL11.GL_DEPTH_TEST);
	}


Model:
private int vbo;
	private int size;
	
	public Model() {
		vbo = GL15.glGenBuffers();
		size = 0;
	}
	
	public void bufferVertices(Vertex[] vertices) {
		FloatBuffer buffer = BufferUtils.createFloatBuffer(vertices.length * Vertex.SIZE);
		for(Vertex v : vertices) {
			buffer.put(v.getX());
			buffer.put(v.getY());
			buffer.put(v.getZ());
		}
		buffer.flip();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		size = vertices.length;
	}

	public int getVbo() {
		return vbo;
	}

	public int getSize() {
		return size;
	}

- A partial, semi-half game developer

Zin

You can check out my code and try to render it that way or just use my engine here: https://github.com/HydraulicHydrox/ZE1

yoojeen

2Zin: Your demo made for LWJGL3?

import org.lwjgl.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;

is disabled and not work.

LWJGL3 haven't org.lwjgl.util.vector package

i got vector folder with classes from lwjgl2.9.1, and... nothing!



isn't work