LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 03-15-2010, 01:08 AM   #1
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Rep: Reputation: Disabled
OpenGL and GLUT in Fedora 12: windows too small and don't resize


I have verified using yum that I have the most uptodate glut, freeglut, freeglut-devel etc., yet when I compile Example 2-6 from the Red Book at http://www.glprogramming.com/red/chapter02.html#name16, I get a window that is too small for the program output, includes display from other windows, and will not redraw after being resized.

I get slightly better behavior with the SGI sample program mentioned in the same book, 'checkers.c'. Again, the initial size is too small, but at least it will resize and redraw the checkerboards entirely inside the resized window.

What is going on here? Is this some bug in glut? I can't see anything obviously wrong in their glut initialization, which looks like:

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (350, 150);
// glutInitWindowSize (700, 300); // did not help
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;

Then again, since I am such a newbie to glut, I am not sure I would recognize what, if anything, they did wrong.

But I have a simpler question: what ARE the valid and useful command line parameters I could have passed to the main() above?
 
Old 03-15-2010, 01:44 AM   #2
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Rep: Reputation: 32
this part looks good to me,
what does your reshape function look like?


Quote:
But I have a simpler question: what ARE the valid and useful command line parameters I could have passed to the main() above?
I'm don't know of any command line arguments for this, although there may be some I don't know, it should run fine without any arguments,./myProgram

Last edited by vendtagain; 03-15-2010 at 01:54 AM.
 
Old 03-15-2010, 02:33 PM   #3
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by vendtagain View Post
this part looks good to me,
what does your reshape function look like?
Thanks for the quick reply. It is:



void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
 
Old 03-15-2010, 04:29 PM   #4
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
After you call gluOrtho2D, try calling

Code:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
 
Old 03-15-2010, 10:49 PM   #5
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by devnull10 View Post
After you call gluOrtho2D, try calling

Code:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
O...K..., following your suggestion I now have:

Code:
void reshape (int w, int h)
{
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

}
At first glance, I thought this was unconditionally worse, since nothing shows up after resizing using the mouse. But after switching windows back to this browser window and then back yet again o the program output, I see the upper inch or so of the desired output -- clipped at the very bottom of the Fedora (GTK?) window!

So the placement in the output window is still very wrong, but once it is forced to redraw after losing focus, the portion that gets rendered gets rendered correctly.

Does this tell you anything?

BTW: I have both Gnome and KDE loaded on this thing. How do I tell which windowing system it is using? Could this be what is confusing GLUT?
 
Old 03-16-2010, 11:08 AM   #6
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Rep: Reputation: 32
Code:
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
This also looks good. I still have all my code from going through that same guide. I compared both your main and reshape functions to my own, and they are the same. So the code is probably not the problem.(note: i used Mac OSX)

Quote:
I have both Gnome and KDE loaded on this thing. How do I tell which windowing system it is using? Could this be what is confusing GLUT?
If your current desktop isnt showing correctly, try the other. so if you are currently using Gnome for the desktop, switch to KDE and see if you get better results. Or you might also try running it from command line, I think it only requires x11 (though not sure about this).
 
Old 03-16-2010, 12:57 PM   #7
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
Try compiling the following code and see if it works for you. It does on mine:

Code:
  #include <GL/glut.h>

  float r= 0.0;
  int hidden= 1, flat= 1;
  
  void init(void) {
     glClearColor (0.0, 0.0, 0.0, 0.0);
     glEnable (GL_LIGHTING);
     glEnable (GL_LIGHT0);
  }
  
  void spin (void) {
     r+= 1.0;
     glutPostRedisplay();
  }
  
  void display(void) {
     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

     if (hidden) glEnable(GL_DEPTH_TEST);
     else glDisable(GL_DEPTH_TEST);

     if (flat) glShadeModel (GL_FLAT);
     else glShadeModel (GL_SMOOTH);

     glLoadIdentity ();
     gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
       
     glColor3f (1.0, 0.0, 0.0); 
     glutSolidCube(1.0);          /* Red cube */

     glRotatef(r*2.0, 0, 1, 0);   /* Orbit angle */
     glTranslatef(0.0, 0.0, 1.0); /* Orbit radius */
     glRotatef(r, 1, 0, 0);       /* Tumble in x,y,z */
     glRotatef(r, 0, 1, 0);
     glRotatef(r, 0, 0, 1);
     glColor3f (0.0, 1.0, 0.0);
     glutSolidSphere(0.5, 20, 15); /* Green sphere */

     glutSwapBuffers();
  }
  
  void reshape (int w, int h) {
     glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
     glMatrixMode (GL_PROJECTION);
     glLoadIdentity ();
     gluPerspective (60, (GLfloat) w / (GLfloat) h, 1.0, 100.0);
     glMatrixMode (GL_MODELVIEW);
  }

  void keyboard(unsigned char key, int x, int y) {
    if (key == 27) { exit (0); } /* escape key */
    if (key == 'h') hidden= !hidden;
    if (key == 's') flat= !flat;
  }

 int main(int argc, char **argv) {
     glutInit(&argc, argv);
     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
     glutInitWindowSize (500, 500); 
     glutInitWindowPosition (100, 100);
     glutCreateWindow ("ex9");
     init ();
     glutDisplayFunc (display); 
     glutReshapeFunc (reshape);
     glutKeyboardFunc (keyboard);
     glutIdleFunc (spin);
     glutMainLoop ();
     return 0;
  }

Last edited by devnull10; 03-16-2010 at 12:58 PM.
 
1 members found this post helpful.
Old 03-16-2010, 04:16 PM   #8
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by devnull10 View Post
Try compiling the following code and see if it works for you. It does on mine:

Code:
  #include <GL/glut.h>
...
  float r= 0.0;
  int hidden= 1, flat= 1;
 int main(int argc, char **argv) {
     glutInit(&argc, argv);
     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
     glutInitWindowSize (500, 500); 
     glutInitWindowPosition (100, 100);
     glutCreateWindow ("ex9");
     init ();
     glutDisplayFunc (display); 
     glutReshapeFunc (reshape);
     glutKeyboardFunc (keyboard);
     glutIdleFunc (spin);
     glutMainLoop ();
     return 0;
  }
Cool! It painted a white square in the middle, and showed an orbiting polyhedral approximation to a sphere.

Since it was right in the middle, and did not require any switching in/out of focus, I assume it worked flawlessly.

So what does this tell us?
 
Old 03-16-2010, 04:19 PM   #9
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by vendtagain View Post
Code:
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
}
This also looks good. I still have all my code from going through that same guide. I compared both your main and reshape functions to my own, and they are the same. So the code is probably not the problem.(note: i used Mac OSX)


If your current desktop isnt showing correctly, try the other. so if you are currently using Gnome for the desktop, switch to KDE and see if you get better results. Or you might also try running it from command line, I think it only requires x11 (though not sure about this).
Since I only installed KDE-base to run Konqueror and Krita, I am not even sure how this is done

Then again, it may not even be relevant after all, since in fact, I have always invoked the OpenGL sample programs from the command line, usually Gnome's Terminal, very rarely KDE's Konsole, which, however, gave the identical results.

So, for example, I named devnull10's code 'Ex9.c', compiled with "gcc -o Ex9 -lglut Ex9.c" and ran with "./Ex9" to see much better results.
 
Old 03-16-2010, 05:47 PM   #10
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by mejohnsn View Post
Cool! It painted a white square in the middle, and showed an orbiting polyhedral approximation to a sphere.

Since it was right in the middle, and did not require any switching in/out of focus, I assume it worked flawlessly.

So what does this tell us?
Then again, now that I actually paused to read the code, I see that no, it is not working flawlessly: the only sphere drawn is white, not green, though the code should have drawn a green sphere with:
Code:
  glColor3f (0.0, 1.0, 0.0);
  glutSolidSphere(0.5, 20, 15); /* Green sphere */
But there really is only one sphere, and it is greyish white.
 
Old 03-16-2010, 05:53 PM   #11
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by mejohnsn View Post
So what does this tell us?
Well, it tells us that your system can render OpenGL applications properly and the reason that your application isn't doing is likely an issue with your matrices, projection coordinates, or something similar, rather than an actual system error.

[edit]
Just seen your post about the colours - not too sure about that - I'll take a look later, just in the middle of something now!

Last edited by devnull10; 03-16-2010 at 05:55 PM.
 
Old 03-26-2010, 11:41 PM   #12
mejohnsn
Member
 
Registered: Sep 2009
Posts: 172

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by devnull10 View Post
Well, it tells us that your system can render OpenGL applications properly and the reason that your application isn't doing is likely an issue with your matrices, projection coordinates, or something similar, rather than an actual system error.

[edit]
Just seen your post about the colours - not too sure about that - I'll take a look later, just in the middle of something now!
Any ideas about the colors? Could this be a bug in the OpenGL libraries I am using? Do I need lighting commands to be a workaround for a bug?

I can't remember how to view what version of OpenGl and GLUT I have, but I do remember installing the most up-to-date available as packages for Fedora; I did the install within the last three weeks.
 
Old 03-27-2010, 04:08 AM   #13
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 547

Rep: Reputation: 115Reputation: 115
Try this - rename the attachment to ex4.tar and then extract. I think the example I provided might have been a poor one - it was just one I pulled from my old uni archive!
This is one I wrote when at uni.
Attached Files
File Type: txt ex4.txt (40.0 KB, 2 views)
 
0 members found this post helpful.
  


Reply

Tags
fedora, glut, graphics, opengl


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie to opengl/glut true_atlantis Programming 3 08-28-2005 08:39 PM
[opengl+glut]Please help me hylke Programming 2 05-10-2004 02:16 AM
problem OpenGL - glut vihan Programming 5 04-17-2004 06:53 AM
glut (Opengl kompilierung) snu *BSD 1 01-20-2004 05:15 PM
glut/mesa/openGL gurra Programming 1 10-10-2001 03:36 PM


All times are GMT -5. The time now is 01:32 AM.

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