Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glTranslatef does not work

Tags:

opengl

lwjgl

In my project I want to render rain, so I use particles.

My render method:

public void draw(Camera camera) {
    glBegin(GL_POINTS);     
    glPushMatrix();

    glTranslatef(camera.getX(), camera.getEyeLevel(), camera.getY());

    glColor4f(0, 0, 0.8f, 0.1f);

    for(int i = 0; i < _currentParticlesCount; i++)
    {
        _particles[i].draw();
    }

    glPopMatrix();
    glEnd();
}

Rain particle init method:

particle.setX(Utils.RANDOM.nextFloat() * RAIN_RADIUS * (Utils.RANDOM.nextBoolean() ? 1 : -1));
particle.setY(Utils.RANDOM.nextFloat() * RAIN_RADIUS);
particle.setZ(Utils.RANDOM.nextFloat() * RAIN_RADIUS * (Utils.RANDOM.nextBoolean() ? 1 : -1));

You see that I want to translate all the particles to the camera's place - relative to player. But there is one problem, glTranslatef simply does n't work. So I see all the particles in the beginning of the world's coordinate system.

In fact, when I draw stars (particles) using the same principle, glTranslatef works properly.

Stars render method:

glDisable(GL_DEPTH_TEST);

glPushMatrix();     
glTranslatef(camera.getX(), camera.getEyeLevel(), camera.getY());

glBegin(GL_POINTS);

glColor3f(1, 1, 1);

for(int i = 0; i < STARS_COUNT; i++) {
    _starsArray[i].draw();
}

glEnd();

glPopMatrix();
glEnable(GL_DEPTH_TEST);

What am I doing wrong?

P. S. I use OpenGL 1.1 LWJGL, Java OpenGL wrapper (lwjgl.org)

like image 876
Кирилл Белов Avatar asked Mar 28 '26 01:03

Кирилл Белов


1 Answers

glTranslatef won't work because it's between glBegin/glEnd.

You can use glGetError() (eg) to make finding bugs like this easier.

like image 67
jozxyqk Avatar answered Mar 29 '26 15:03

jozxyqk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!