Render bug?

Started by Skatty, July 13, 2013, 09:23:40

Previous topic - Next topic

Skatty

Hello

I wanna make simple clouds built from quads.

So i made Cloud class and i init it from my Main by using:

Cloud.init(52.0f)


but clouds are not rendered

Cloud.java:
package skatty.enviroment;

import java.util.Random;
import org.lwjgl.opengl.GL11;

import skatty.Main;
import skatty.World;

public class Cloud {
	
	static float SKYheight = 0.7f;
	static float SKYwidth = 1.5f;
	static float SKYlength = 1.5f;
	static float textureSize = 1.0f;
	static float spriteX = 0.0f;
	static float spriteY = 0.0f;
	static float height;
	static float x1 = 0.0f;
	static float y1 = height;
	static float z1 = 0.0f;
	
	
	Random generator;
	
	public static void init(float CloudsHeight) {
		height = CloudsHeight;
		System.out.println(height);
		render();
	}
	
	
	public static void generateClouds(int side) {
		switch(side) {
		
		case 1: //bot
			Main.sky.bind();
			GL11.glBegin(GL11.GL_LINE_LOOP);
			GL11.glBegin(GL11.GL_TRIANGLES); 
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX, spriteY + textureSize);
			GL11.glVertex3f(x1, y1, z1+SKYlength); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1+SKYwidth, y1, z1+SKYlength); // 3
			  		
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX + textureSize, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1, z1); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1+SKYwidth, y1, z1+SKYlength); // 3
			GL11.glEnd();
			break;

		case 2: //top
			 
			GL11.glBegin(GL11.GL_TRIANGLES); 
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1 + SKYheight, z1); // 1	
			GL11.glTexCoord2f(spriteX, spriteY + textureSize);
			GL11.glVertex3f(x1, y1 + SKYheight, z1+SKYlength); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1+SKYwidth, y1 + SKYheight, z1+SKYlength); // 3
			  		
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1 + SKYheight, z1); // 1	
			GL11.glTexCoord2f(spriteX + textureSize, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1+SKYwidth, y1 + SKYheight, z1+SKYlength); // 3
			GL11.glEnd();
			break;

		case 3: //back
			 
			GL11.glBegin(GL11.GL_TRIANGLES); 
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX + textureSize, spriteY);
			GL11.glVertex3f(x1, y1, z1 + SKYlength); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1, y1 + SKYheight, z1+SKYlength); // 3
			  		
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX, spriteY + textureSize);
			GL11.glVertex3f(x1, y1 + SKYheight, z1); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1, y1 + SKYheight, z1+SKYlength); // 3
			GL11.glEnd();
			break;

		case 4: //front
			 
			GL11.glBegin(GL11.GL_TRIANGLES); 
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX + textureSize, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1, z1 + SKYlength); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1+SKYlength); // 3
			  		
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1+SKYlength); // 3
			GL11.glEnd();	
			break;

		case 5: //left
			 
			GL11.glBegin(GL11.GL_TRIANGLES); 
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1+SKYlength); // 1	
			GL11.glTexCoord2f(spriteX, spriteY + textureSize);
			GL11.glVertex3f(x1, y1 + SKYheight, z1+SKYlength); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1+SKYlength); // 3
			  		
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1+SKYlength); // 1	
			GL11.glTexCoord2f(spriteX+ textureSize, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1, z1+SKYlength); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1+SKYlength); // 3
			GL11.glEnd();	
			break;

		case 6: //right
			 
			GL11.glBegin(GL11.GL_TRIANGLES); 
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX, spriteY + textureSize);
			GL11.glVertex3f(x1, y1 + SKYheight, z1); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1); // 3
			  		
			GL11.glTexCoord2f(spriteX, spriteY);
			GL11.glVertex3f(x1, y1, z1); // 1	
			GL11.glTexCoord2f(spriteX+ textureSize, spriteY);
			GL11.glVertex3f(x1 + SKYwidth, y1, z1); // 2
			GL11.glTexCoord2f(spriteX + textureSize, spriteY + textureSize);
			GL11.glVertex3f(x1 + SKYwidth, y1 + SKYheight, z1); // 3
			GL11.glEnd();	
			break;
	}
	}
	
	public static void render() {
		GL11.glColor3f(1, 1, 1);
		GL11.glBegin(GL11.GL_TRIANGLES);
		for (int a = 0; a < World.BLOCK_AMOUNT_AT_AXIS/4; a++) {
			for (int b = 0; b < World.BLOCK_AMOUNT_AT_AXIS/4; b++) {
				generateClouds(1);
				generateClouds(2);
				generateClouds(3);
				generateClouds(4);
				generateClouds(5);
				generateClouds(6);
			}
		}
	GL11.glEnd();
	
	}	
}

Fool Running

The first thing that jumps out at me is:
GL11.glBegin(GL11.GL_LINE_LOOP);
GL11.glBegin(GL11.GL_TRIANGLES);

You can't call a glBegin() inside a glBegin()/glEnd().
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D