Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-09-2004, 12:43 AM
|
#1
|
Member
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223
Rep:
|
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
|
|
|
07-09-2004, 01:28 AM
|
#2
|
Member
Registered: Apr 2004
Posts: 101
Rep:
|
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
Last edited by gizmo_thunder; 07-09-2004 at 01:35 AM.
|
|
|
07-09-2004, 08:13 AM
|
#3
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
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.
|
|
|
07-09-2004, 08:44 AM
|
#4
|
Member
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223
Original Poster
Rep:
|
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  I was thinking there might be a teapot somewhere so I changed the color but nope  any ideas?
|
|
|
07-09-2004, 10:39 AM
|
#5
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
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.
|
|
|
07-09-2004, 10:48 AM
|
#6
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
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;
}
|
|
|
07-09-2004, 01:36 PM
|
#7
|
Member
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223
Original Poster
Rep:
|
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
|
|
|
07-09-2004, 01:41 PM
|
#8
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
BTW, on a totally off-topic tangent based on your sig...
Have you read book 6 yet? Book 7 will be out Sept 21!!! 
|
|
|
07-09-2004, 05:22 PM
|
#9
|
Member
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223
Original Poster
Rep:
|
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
|
|
|
07-10-2004, 12:53 AM
|
#10
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Rep:
|
poeta_boy Glut sucks!!! Look into SDL and make the headaches go away!
www.libsdl.org

|
|
|
07-10-2004, 01:12 AM
|
#11
|
Member
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223
Original Poster
Rep:
|
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 
|
|
|
07-10-2004, 01:47 PM
|
#13
|
Member
Registered: Aug 2002
Distribution: Debian
Posts: 540
Rep:
|
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.
|
|
|
07-11-2004, 11:38 AM
|
#14
|
Member
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895
Rep:
|
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...
|
|
|
07-11-2004, 04:40 PM
|
#15
|
Member
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223
Original Poster
Rep:
|
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!!
Last edited by poeta_boy; 07-11-2004 at 04:43 PM.
|
|
|
All times are GMT -5. The time now is 08:18 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|