LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-02-2023, 12:11 PM   #1
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 271

Rep: Reputation: Disabled
display callback fails after dist upgrade


william@geeves:~/projects/gnutran$ uname -a
Linux geeves 6.1.0-13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.55-1 (2023-09-29) x86_64 GNU/Linux
libglut-dev 3.4.0-1

I tried to run a program that used to run perfectly, and received the error:
./gnutran: error while loading shared libraries: libglut.so.3: cannot open shared object file: No such file or directory

So I recompiled the program, ran it and got:
freeglut (./gnutran): ERROR: No display callback registered for window 2

Subject code:
Code:
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
//    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(WindowWidth, WindowHeight);
    glutInitWindowPosition(100, 100);
  mainWindow = glutCreateWindow(argv[1]);
  glutReshapeFunc(reshape);
  
  glutInitWindowSize(TWindowWidth, TWindowHeight);
  glutInitWindowPosition(800, 200);
  textWindow = glutCreateWindow("textbox");
  glutReshapeFunc(reshapeText);
  
  glutSetWindow(mainWindow);
    GLenum err = glewInit();
    if (GLEW_OK != err){
      /* Problem: glewInit failed, something is seriously wrong. */
      fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
    }
  init();
  glutDisplayFunc(display);
  glutDisplayFunc(displayText);
Presumably it does not like something about
Code:
glutDisplayFunc(displayText)
Can someone give me a clue?
 
Old 12-03-2023, 12:29 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,986
Blog Entries: 1

Rep: Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908Reputation: 1908
Please provide a minimal complete verifiable example.
https://stackoverflow.com/help/minim...ucible-example
 
Old 12-04-2023, 03:03 PM   #3
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 271

Original Poster
Rep: Reputation: Disabled
Verifiable example:
Note that lines 63 - 66, 69 (window 2) are commented out. The result is similar to a "Hello World", and displays window1.
If instead I comment out lines 58 - 61, 68 (window 1) and recompile, window2 is displayed.
If none of the code is commented out, the result is the error message:
Quote:
freeglut (./reshape_test): ERROR: No display callback registered for window 1
Code:
// reshape_test.c
// compile as gcc reshape_test.c -o reshape_test -lglut -lGLEW -lGL

#include <GL/glut.h>
int firstWindow, secondWindow;

void display1(){
	glutSetWindow(firstWindow);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
	glColor3f(0.0, 1.0, 0.0);
	
	glBegin(GL_POLYGON);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.5, 0.0, 0.0);
	glVertex3f(0.5, 0.5, 0.0);
	glVertex3f(0.0, 0.5, 0.0);
	glEnd();
	
	glFlush();
	glutSwapBuffers();
}

void display2(){
	glutSetWindow(secondWindow);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();
	glColor3f(1.0, 0.0, 0.0);
	
	glBegin(GL_POLYGON);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.5, 0.0, 0.0);
	glVertex3f(0.5, 0.5, 0.0);
	glVertex3f(0.0, 0.5, 0.0);
	glEnd();
	
	glutSwapBuffers();
	glFlush();
}

void reshape1(int w, int h){
  glutSetWindow(firstWindow); 
  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  display1();
}

void reshape2(int w, int h){
  glutSetWindow(secondWindow); 
  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  display2();
}

int main(int argc, char* argv[]){
	glutInit(&argc,argv);
  glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(300,100);
  glutInitWindowPosition(100, 100);
  firstWindow = glutCreateWindow("1st_window");
  glutReshapeFunc(reshape1);
  
/*	glutInitWindowSize(300,100);
  glutInitWindowPosition(600, 100);
  secondWindow = glutCreateWindow("2nd_window");
  glutReshapeFunc(reshape2);*/
  
  glutDisplayFunc(display1);
//  glutDisplayFunc(display2);
  
  glutMainLoop();
  return 0;
}
 
Old 12-04-2023, 07:54 PM   #4
EdGr
Senior Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 1,058

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
The order matters.

You need to create the first window and set its reshape and display callbacks, and then create the second window and set its reshape and display callbacks.
Ed

Code:
// reshape_test.c
// compile as gcc reshape_test.c -o reshape_test -lglut -lGLEW -lGL

#include <GL/glut.h>
int firstWindow, secondWindow;

void display1(){
  glutSetWindow(firstWindow);
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  glLoadIdentity();
  glColor3f(0.0, 1.0, 0.0);

  glBegin(GL_POLYGON);
  glVertex3f(0.0, 0.0, 0.0);
  glVertex3f(0.5, 0.0, 0.0);
  glVertex3f(0.5, 0.5, 0.0);
  glVertex3f(0.0, 0.5, 0.0);
  glEnd();

  glFlush();
  glutSwapBuffers();
}

void display2(){
  glutSetWindow(secondWindow);
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  glLoadIdentity();
  glColor3f(1.0, 0.0, 0.0);

  glBegin(GL_POLYGON);
  glVertex3f(0.0, 0.0, 0.0);
  glVertex3f(0.5, 0.0, 0.0);
  glVertex3f(0.5, 0.5, 0.0);
  glVertex3f(0.0, 0.5, 0.0);
  glEnd();

  glutSwapBuffers();
  glFlush();
}

void reshape1(int w, int h){
  glutSetWindow(firstWindow);
  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  display1();
}

void reshape2(int w, int h){
  glutSetWindow(secondWindow);
  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  display2();
}

int main(int argc, char* argv[]){
  glutInit(&argc,argv);
  glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  glutInitWindowSize(300,100);
  glutInitWindowPosition(100, 100);
  firstWindow = glutCreateWindow("1st_window");
  glutReshapeFunc(reshape1);
  glutDisplayFunc(display1);

  glutInitWindowSize(300,100);
  glutInitWindowPosition(600, 100);
  secondWindow = glutCreateWindow("2nd_window");
  glutReshapeFunc(reshape2);
  glutDisplayFunc(display2);

  glutMainLoop();
  return 0;
}
 
1 members found this post helpful.
Old 12-04-2023, 09:04 PM   #5
piobair
Member
 
Registered: Aug 2013
Distribution: Debian, Ubuntu
Posts: 271

Original Poster
Rep: Reputation: Disabled
So all that I needed to do was move the
Code:
glutDisplayFunc(display1);
up six lines. I tried that, and it works. Thank you
The original code snippet that I provided is over a decade old. I wonder why it never bombed before.

Quote:
Originally Posted by EdGr View Post
The order matters.

You need to create the first window and set its reshape and display callbacks, and then create the second window and set its reshape and display callbacks.
Ed
 
Old 12-05-2023, 09:37 AM   #6
EdGr
Senior Member
 
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 1,058

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by piobair View Post
The original code snippet that I provided is over a decade old. I wonder why it never bombed before.
The library likely changed. This is an old-style API that relies on a global variable (the current window).
Ed
 
  


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
Ubuntu fails to boot after dist-upgrade freeindy Ubuntu 6 03-10-2016 09:04 PM
[SOLVED] Upgrade from Wheezy to Jessie fails after apt-get dist-upgrade Angoid Debian 17 01-07-2016 02:25 AM
Install one new dist from within another dist psykner Linux - Software 9 10-10-2011 01:26 AM
Wireless switch doesn't work after upgrade/dist-upgrade angelofhope Debian 10 01-02-2008 04:46 AM
RPM-dist to Source dist GAVollink Linux - Distributions 4 08-16-2002 10:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration