Hello world ! I am beginner in openGL and really facing difficulties while learning it. I have a question and getting confused about the usage of GL_PROJECTIOn and GL_MODELVIEW and also about glLoadIdentity(). I am struggling, this concept has consumed several hours of mine. So from World, anyone who can remove my confusion where these concepts are used.

Recommended Answers

All 3 Replies

A simple way to think about it is that GL_PROJECTION is to camera and GL_MODELVIEW is to world objects.

So if you use glTranslatef() in projection mode then you will be moving your viewing position or camera. And if you translate in modelview then you are moving the drawing point for objects.

glLoadIdentity() just takes the view that you passed into glMatrixMode() and loads it as the current matrix.

Thanks SFUO ! Now I understood the concept....can you help me in the below code ?:-
I stuck in a step for screen boundation for ball which is moving in counter clockwise direction..
How to apply screen boundation with coordinate system...Plzzz help me in this code...

if(posx<=1.0-radius && posy<=0.5)  // RIGHT EDGE RESTRICTION
dx=(1.0-radius)-posx;   // +
dy=0.5-posy;     // +
glColor3f(1.0,0.0,1.0);   // COLOUR OF THE BALL
    if(posx>=0.5 && posy<=(1.0-radius))  // TOP EDGE RESTRICTION
    dx=0.5-posx;   // -     
    dy=(1.0-radius)-posy;   // +
    glColor3f(1.0,1.0,0.0);   // COLOUR OF THE BALL
        if(posx>=0.0+radius && posy>=0.5)  // LEFT EDGE RESTRICTION
        dx=(0.0+radius)-posx;  //  -
        dy=(0.5-posy); //  -
        glColor3f(0.0,1.0,1.0);   // COLOUR OF THE BALL
            if(posx<=0.5 && posy>=0.0+radius)
            dx=0.5-posx;    // +
            dy=(0.0+radius)-posy;   // - 
            glColor3f(1.0,1.0,1.0);   // COLOUR OF THE BALL

dis=sqrt(dx*dx+dy*dy);  // Distance between Ball and Wall
speedx=dx/(dis*100);    // Normalizing x
speedy=dy/(dis*100);    // Normalizing y

for (float angle = 0;angle<360;angle+=5)
    float xc=sin(angle*PI/180) * radius;
    float yc=cos(angle*PI/180) * radius;
    glVertex3f(xc+posx, yc+posy ,0.0f);

Plz help me to set screen edge boundation for ball ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.