Main Menu

Beginner Q

Started by NickyP101, May 02, 2005, 10:05:20

Previous topic - Next topic

NickyP101

Please take a look at the code below, can u tell me why eventually after a couple loops of my program my quad dissapears (is no longer visible on the screen). When i say a couple loops im just estimating.

public void gameLoop(){

		try{
			while(!finnish){

				update();
				render();
				display.update();

			}

			cleanup();
			
		}catch(Exception e){System.out.println(e);}


	}

                public void render() { 

       		gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);          // Clear The Screen And The Depth Buffer 
       		gl.glLoadIdentity();                          // Reset The Current Modelview Matrix 	

		gl.glTranslatef(0.0f,0.0f,-6.0f);  



		for(int y1 = 0; y < 5; y++){
		
			for(int x1 = 0; x < 5; x++){

       				gl.glBegin(gl.GL_QUADS);      	  
           				gl.glVertex3f( -1.0f, 1.0f, 0.0f);         
           				gl.glVertex3f(-1.0f,-1.0f, 0.0f);         
           				gl.glVertex3f( 1.0f,-1.0f, 0.0f);         
       					gl.glVertex3f( 1.0f,1.0f, 0.0f);
				gl.glEnd(); 

			}

		
		}	

		
   	}


Cheers, Nick

princec

Because you are every loop translating the modelview matrix by a further 6.0f units out of the Z plane!

You need to do this:
glPushMatrix();
glTranslatef(x,y,z);
// Draw here
glPopMatrix();


Cas :)

NickyP101

Sorry no luck there:

Here is the code again, my first one was formatted incorrectly.

public void gameLoop(){

		try{
			while(!finnish){

				update();
				render();
				display.update();

				Thread.sleep(1000);

			}

			cleanup();
			
		}catch(Exception e){System.out.println(e);}


	}

   	public void render() { 

       		gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);          // Clear The Screen And The Depth Buffer 
       		gl.glLoadIdentity();                          // Reset The Current Modelview Matrix 

		gl.glTranslatef(0.0f, 0.0f, -6.0f);


		for(int y1 = 0; y < 5; y++){
		
			for(int x1 = 0; x < 5; x++){
			
       				gl.glBegin(gl.GL_QUADS);      	   // Drawing Using Quads
           				gl.glVertex3f( -1.0f, 1.0f, 0.0f);         // Top Left
           				gl.glVertex3f(-1.0f,-1.0f, 0.0f);         // Bottom Left 
           				gl.glVertex3f( 1.0f,-1.0f, 0.0f);         // Bottom Right 
       					gl.glVertex3f( 1.0f,1.0f, 0.0f);	  //Top right
				gl.glEnd(); 


			}

		
		}	



		
   	}


If i get rid of the two for loops its works fine, ive tried to use glPushMatrix and PopMatrix but they didnt work.

Am i incorrect in saying that gl.glLoadIdentity(); sets it back to 0,0,0.

princec

Try removing the translate and see if it works.

Cas :)

NickyP101

Did, doesnt work. I cant see how the problem can relate to the glTranslatef. Because if i remove to two for loops its works fine. Its weird, lol i always get this kinda stuff happening when i start new things. Below ill paste my init code:

public void glInit(){

		try{

			gl.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping 
       			gl.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading 
       			gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background 
       			gl.glClearDepth(1.0); // Depth Buffer Setup 
       			gl.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing 
       			gl.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do 

       			gl.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix 
       			gl.glLoadIdentity(); // Reset The Projection Matrix 

       			// Calculate The Aspect Ratio Of The Window 
       			glu.gluPerspective( 
         			45.0f, 
         			(float) display.getDisplayMode().getWidth() / (float) display.getDisplayMode().getHeight(), 
         			0.1f, 
         			100.0f); 
       			gl.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix 

       			// Really Nice Perspective Calculations 
       			gl.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); 


		

		}catch(Exception e){System.out.println(e);}

	}


Cheers, Nick

princec

for(int y1 = 0; y < 5; y++){
     
        for(int x1 = 0; x < 5; x++){

very suspect looking loops there...


Cas :)

NickyP101

Haha i dont quiet know what u mean there, and to thell you the truth there is no point of having the loops, i was just playing around and this happened.

NickyP101

Haha jeez sorry just saw that lol thats shoking i my behalf sorry for wasting ur time lol cant believe i didnt see that, i looked at them so closely, must been looking to closely lol

princec