LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   simple program using openGL in GLUT (https://www.linuxquestions.org/questions/programming-9/simple-program-using-opengl-in-glut-202896/)

poeta_boy 07-09-2004 12:43 AM

simple program using openGL in GLUT
 
hello please I need some help:

I have this little program on c++ using GLUT

Code:

#include <GL/GL/glut.h>
#include <stdlib.h>

void Reshape(int w, int h)
{
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);       
        glLoadIdentity();
        glOrtho(-1, 1, -1, 1, -10, 10);
}
void Display(void)
{
        glClear(GL_COLOR_BUFFER_BIT);               
        glutWireTeapot(0.6);                               
        glFlush();                                                       
}
int main(int argc, char** argv)
{
        glutInit(&argc, argv);                               
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
        glutCreateWindow("Mi primer ventana");       
        glutInitWindowSize(500,500);
        glutDisplayFunc(Display);                                       
        glutReshapeFunc(Reshape);                                       
        glutMainLoop();
        return 0;
}

but I can't get to make it work, it does compile but just appears an empty window (empty as if it was transparent, as with a whole where you can see through)

thanks a lot for your time.

Poeta

gizmo_thunder 07-09-2004 01:28 AM

Code:

#include <GL/GL/glut.h>
#include <stdlib.h>

void Reshape(int w, int h)
{
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);       
        glLoadIdentity();
        glOrtho(-1, 1, -1, 1, -10, 10);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
}
void Display(void)
{
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);               
        glutWireTeapot(0.6);                               
        glFlush();                                                       
}
int main(int argc, char** argv)
{
        glutInit(&argc, argv);                               
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
        glutCreateWindow("Mi primer ventana");       
        glutInitWindowSize(500,500);
        glEnable(DEPTH_TEST);
        glutDisplayFunc(Display);                                       
        glutReshapeFunc(Reshape);                                       
        glutMainLoop();
        return 0;
}

Made some change try it

deiussum 07-09-2004 08:13 AM

Add glutSwapBuffers to the end of your Display() function. You are requesting a double buffer with the GLUT_DOUBLE, but you never swap the buffers.

poeta_boy 07-09-2004 08:44 AM

Thanks for your responses. I've done what you guys said, and this is how it looks:

Code:

#include <GL/GL/glut.h>
#include <stdlib.h>

void Reshape(int w, int h)
{
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);       
        glLoadIdentity();
        glOrtho(-1, 1, -1, 1, -10, 10);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

}
void Display(void)
{
        glClear(GL_COLOR_BUFFER_BIT);               
        glColor3f(1,1,1);
        glutWireTeapot(0.6);
        glutSwapBuffers();                       
        glFlush();                                                       
}
int main(int argc, char** argv)
{
        glutInit(&argc, argv);                               
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
        glutCreateWindow("Mi primer ventana");       
        glutInitWindowSize(500,500);
       
        glEnable(GL_DEPTH_TEST);       
       
        glutDisplayFunc(Display);                                       
        glutReshapeFunc(Reshape);                                       
        glutMainLoop();
        return 0;
}

now it appears a black windows, not just the one with a "hole", however no teapot :confused: I was thinking there might be a teapot somewhere so I changed the color but nope :( any ideas?

deiussum 07-09-2004 10:39 AM

I don't see anything that would cause you not to see the teapot off the top of my head, but a couple of things I do see is that you have glutSwapBuffers before glFlush. glFlush should go before glutSwapBuffers, though technically, it's not even needed because glutSwapBuffers will flush before it swaps, anyway...

Also, you enable depth test, but you don't have GLUT_DEPTH in your glutInit params. Without that, you may not get a depth buffer to begin with in order for your depth test to work.

Neither of those problems should cause you not to see the teapot, though. Have you tried glutSolidTeapot, just to make sure you're just not missing the wireframe?

The projection matrix looks ok, so your teapot should be within the viewing frustum...
you're not enabling lighting, so it's not a material/normal/lighting problem...

If I get a chance I'll try to compile that on my system and see if I am missing anything.

deiussum 07-09-2004 10:48 AM

One other thing you aren't doing is clearing the depth buffer by adding GL_DEPTH_BUFFER_BIT in the bitmask for glClear...

Here's the program with those changes. It seems to work fine for me:

Code:

// This seems odd too, usually glut.h is directly under GL/glut.h,
// not GL/GL/glut.h, but if it compiles for you....
#include <GL/GL/glut.h>
#include <stdlib.h>

void Reshape(int w, int h)
{
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);       
        glLoadIdentity();
        glOrtho(-1, 1, -1, 1, -10, 10);

              glMatrixMode(GL_MODELVIEW);
              glLoadIdentity();

}
void Display(void)
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);               
        glColor3f(1,1,1);
        glutWireTeapot(0.6);
        glutSwapBuffers();                       
}
int main(int argc, char** argv)
{
        glutInit(&argc, argv);                               
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
        glutCreateWindow("Mi primer ventana");       
        glutInitWindowSize(500,500);
               
        glEnable(GL_DEPTH_TEST);

        glutDisplayFunc(Display);                                       
        glutReshapeFunc(Reshape);                                       
        glutMainLoop();
        return 0;
}


poeta_boy 07-09-2004 01:36 PM

hello!

thanks thanks a lot I can see it now.... it's odd since I have this other program also displaying a teapot but with the ability to rotate it pressing space bar.... and that one worked right away....

I use GL/GL/glut because that's my dir tree... even tough I've seen it should be only one GL, I'll change it right now.

Thanks!!!! I appreciate it

deiussum 07-09-2004 01:41 PM

BTW, on a totally off-topic tangent based on your sig...

Have you read book 6 yet? Book 7 will be out Sept 21!!! :)

poeta_boy 07-09-2004 05:22 PM

mmm sorry what do you mean? hehe are you talking about king crimson??
I love it?s music!!! but books??? i only know about one book of King Crimson band is that what you meant??

hehehe sorry about being so out of fashion!

poeta

The_Nerd 07-10-2004 12:53 AM

poeta_boy Glut sucks!!! Look into SDL and make the headaches go away!

www.libsdl.org

;)

poeta_boy 07-10-2004 01:12 AM

hahahaha I love your signature.... I must use GLUT because it's a requirement at school but I definitly will check that out too!! thanks for the recommendation..........

BTW know of any good tutorial? I don't want to bother you nice guys with silly questions all the time :(

gizmo_thunder 07-10-2004 01:25 AM

Try
http://nehe.gamedev.net its' got the best tutorials :)

The_Nerd 07-10-2004 01:47 PM

Here is the documentation for SDL. Its the only thing I needed to learn how to use SDL. SDL is really simple! There are some examples at the bottom of the page.
http://sdldoc.csn.ul.ie/index.php

You can also find allot of good docs on the SDL web page.


By the way, I thought when you said "gimme' some tuts'" you were talking about SDL. If you are talking about GLUT then I do suggest nehe, or google it.

deiussum 07-11-2004 11:38 AM

Quote:

Originally posted by poeta_boy
mmm sorry what do you mean? hehe are you talking about king crimson??
I love it?s music!!! but books??? i only know about one book of King Crimson band is that what you meant??

hehehe sorry about being so out of fashion!

poeta

Ahh, sorry. I thought maybe it was a reference to the Crimson King in Stephen King's Dark Tower books. :) Don't I feel silly now...

poeta_boy 07-11-2004 04:40 PM

hehehe .......... I was talking about King Crimson the rock band which leader is Robert Fripp... I recommend it and if you have the opportunity you should listen the song called "Matte Kudasai".

It's quite strange but really cool :)

Quote:

Here is the documentation for SDL. Its the only thing I needed to learn how to use SDL. SDL is really simple! There are some examples at the bottom of the page.
I have a lot of things to learn...... I just sometimes feel quite dissapointed of a very high learning curve... it's hard to grow up

I just have to find a passion!!


All times are GMT -5. The time now is 03:57 PM.