• Advertisement
Sign in to follow this  

***Need help with render method***

This topic is 4742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone plz help me with my render method, i have spent i dont know how many hours on it but i just dont understand why i am getting unexpected results my render method is below: private boolean render() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer GL11.glLoadIdentity(); // Reset The Current Modelview Matrix GLU.gluLookAt(0,20,80, 0,0,0, 0,1,0); // This determines where the camera's position and view is renderBackground(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); //added to see models again, set texture form black //to nothing for (int x = 0;x<aliens.length;x++) { aliens[x].renderAliens(); } ship.renderTheShip(); if(bulletCreated) bullet[0].renderBullet(); GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.8f, -2.0f); glPrint("High Score"); // Print GL Text To The Screen GL11.glLoadIdentity(); GL11.glTranslatef(0.0f, 0.7f, -2.0f); //glPrint(playerScore); System.out.println("Player Score = " + playerScore); glPrint("Current Score"); // Print GL Text To The Screen GL11.glLoadIdentity(); GL11.glTranslatef(-6.0f, 4.0f, -12.0f); for (int x = 0;x<smallShips.length;x++) { smallShips[0].renderLives(); } return true; } now with the above i get my aliens in green which is great, a yellow bullet which is great, my text shows up, my model smallShip shows up red which is ok but my background then has red all over it, if i comment out: smallShips[0].renderLives(); everything is ok, so i guess the problem is with that, now the renderLives method is below: public void renderLives() { for(int x =0;x < OpenGLWindow.numLivesLeft();x++) { GL11.glPushMatrix(); GL11.glTranslatef(1.0f,0.0f,0.0f); //move forward renderSmallShip(); GL11.glPopMatrix(); } } and renderSmallShip is below: private void renderSmallShip() { GL11.glColor3f(rColour, gColour, bColour); GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); GL11.glVertexPointer(3, 0, smallShipData); GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, smallShipData.capacity() / 3); GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); //GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } now the color is set to red, any colour i set is what is set over the background too. can anyone plz tell me why, i really cannot sort it very greatful for any replies Danny

Share this post


Link to post
Share on other sites
Advertisement
i don't know why but is see other problem:

public void renderLives()
{
for(int x =0;x < OpenGLWindow.numLivesLeft();x++)
{
GL11.glPushMatrix();
GL11.glTranslatef(1.0f,0.0f,0.0f); //move forward
renderSmallShip();
GL11.glPopMatrix();
}
}

shouldn't it be :

public void renderLives()
{
GL11.glPushMatrix();
for(int x =0;x < OpenGLWindow.numLivesLeft();x++)
{
GL11.glTranslatef(1.0f,0.0f,0.0f); //move forward
renderSmallShip();
}
GL11.glPopMatrix();
}

because as i anderstand you are drawing all small ship one over the other.

also you can use glPushAttrib(GL_ALL_ATTRIB_BITS); glPopAttrib;

Share this post


Link to post
Share on other sites
public void renderLives()

{

GL11.glPushMatrix();

for(int x =0;x < OpenGLWindow.numLivesLeft();x++)

{

GL11.glTranslatef(1.0f,0.0f,0.0f); //move forward

renderSmallShip();

}

GL11.glPopMatrix();

}

this works great! can u explain why though if you don't mind plz

also what does:
glPushAttrib(GL_ALL_ATTRIB_BITS); glPopAttrib;
do?
can i use it in place of the above code?
thanks

Share this post


Link to post
Share on other sites
i get my number of lives showing correctly now but can anyone see wh my models are black and my background is red?
i have the following values that i am using in the above code:
private float rColour = 1.0f;
private float gColour = 0.0f;
private float bColour = 0.0f;
so i can see where the red is coming from but it should draw the models red and not the background,
if it helps i can post more of the code if the problem is probably elsewhere
thanks

Share this post


Link to post
Share on other sites
Pushing a matrix does not push color state. When you set the color to red, it stays that way. Just set it back to white after you're done, and you should be OK.

Note that drawing a vertex array with a color element also changes glColor() state! You have to set it back afterwards.

Share this post


Link to post
Share on other sites
"this works great! can u explain why though if you don't mind plz"
you did pushed/poped matrix in the loop , and it reset the matrix to matrix wich was before the loop begin,and all the glTranslatef was for nothing all model are place [matrix before loop].x=1.0f

"
also what does:
glPushAttrib(GL_ALL_ATTRIB_BITS); glPopAttrib;
do?
can i use it in place of the above code?
"
it save all states of opengl,you can save only specific one,stencil/color/..
for example if you call "glPushAttrib(GL_ALL_ATTRIB_BITS);" before "smallShips[0].renderLives();" and after call "glPopAttrib;" all opengl states will be same as before

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement