LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 07-09-2004, 12:43 AM   #1
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
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
 
Old 07-09-2004, 01:28 AM   #2
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
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.
 
Old 07-09-2004, 08:13 AM   #3
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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.
 
Old 07-09-2004, 08:44 AM   #4
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
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?
 
Old 07-09-2004, 10:39 AM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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.
 
Old 07-09-2004, 10:48 AM   #6
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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;
}
 
Old 07-09-2004, 01:36 PM   #7
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
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
 
Old 07-09-2004, 01:41 PM   #8
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
BTW, on a totally off-topic tangent based on your sig...

Have you read book 6 yet? Book 7 will be out Sept 21!!!
 
Old 07-09-2004, 05:22 PM   #9
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
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
 
Old 07-10-2004, 12:53 AM   #10
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
poeta_boy Glut sucks!!! Look into SDL and make the headaches go away!

www.libsdl.org

 
Old 07-10-2004, 01:12 AM   #11
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
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
 
Old 07-10-2004, 01:25 AM   #12
gizmo_thunder
Member
 
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
Try
http://nehe.gamedev.net its' got the best tutorials
 
Old 07-10-2004, 01:47 PM   #13
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
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.
 
Old 07-11-2004, 11:38 AM   #14
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 31
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...
 
Old 07-11-2004, 04:40 PM   #15
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
openGL, glut and lights on C++ poeta_boy Programming 0 08-02-2004 05:21 PM
[opengl+glut]Please help me hylke Programming 2 05-10-2004 02:16 AM
Compiling a simple Mesa/GLUT program Bojdom Linux - Software 2 02-02-2003 04:19 PM
simple opengl program tundra Programming 6 06-27-2002 11:10 AM
glut/mesa/openGL gurra Programming 1 10-10-2001 03:36 PM


All times are GMT -5. The time now is 08:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration