Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 123225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:15:10+00:00 2026-05-11T04:15:10+00:00

I am making an application that does some custom image processing. The program will

  • 0

I am making an application that does some custom image processing. The program will be driven by a simple menu in the console. The user will input the filename of an image, and that image will be displayed using openGL in a window. When the user selects some processing to be done to the image, the processing is done, and the openGL window should redraw the image.

My problem is that my image is never drawn to the window, instead the window is always black. I think it may have to do with the way I am organizing the threads in my program. The main execution thread handles the menu input/output and the image processing and makes calls to the Display method, while a second thread runs the openGL mainloop.

Here is my main code:

#include <iostream> #include <GL/glut.h> #include 'ImageProcessor.h' #include 'BitmapImage.h'  using namespace std;  DWORD WINAPI openglThread( LPVOID param ); void InitGL(); void Reshape( GLint newWidth, GLint newHeight ); void Display( void );  BitmapImage* b; ImageProcessor ip;   int main( int argc, char *argv[] ) {     DWORD threadID;     b = new BitmapImage();      CreateThread( 0, 0, openglThread, NULL, 0, &threadID );      while( true ) {         char choice;         string path = 'TestImages\\';         string filename;         cout << 'Enter filename: ';         cin >> filename;         path += filename;         b = new BitmapImage( path );         Display();          cout << '1) Invert' << endl;         cout << '2) Line Thin' << endl;         cout << 'Enter choice: ';         cin >> choice;          if( choice == '1' ) {             ip.InvertColour( *b );         }         else {             ip.LineThinning( *b );         }         Display();     }      return 0; }   void InitGL() {     int argc = 1;     char* argv[1];     argv[0] = new char[20];     strcpy( argv[0], 'main' );      glutInit( &argc, argv );      glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);     glutInitWindowPosition( 0, 0 );     glutInitWindowSize( 800, 600 );     glutCreateWindow( 'ICIP Program - Character recognition using line thinning, Hilbert curve, and wavelet approximation' );      glutDisplayFunc( Display );     glutReshapeFunc( Reshape );      glClearColor(0.0,0.0,0.0,1.0);      glEnable(GL_DEPTH_TEST); }   void Reshape( GLint newWidth, GLint newHeight ) {     /*  Reset viewport and projection parameters  */     glViewport( 0, 0, newWidth, newHeight ); }   void Display( void ) {     glClear (GL_COLOR_BUFFER_BIT); // Clear display window.     b->Draw();     glutSwapBuffers(); }   DWORD WINAPI openglThread( LPVOID param ) {     InitGL();     glutMainLoop();     return 0; } 

Here is my draw method for BitmapImage:

void BitmapImage::Draw() {     cout << 'Drawing' << endl;     if( _loaded ) {         glBegin( GL_POINTS );             for( unsigned int i = 0; i < _height * _width; i++ ) {                 glColor3f( _bitmap_image[i*3] / 255.0, _bitmap_image[i*3+1] / 255.0, _bitmap_image[i*3+2] / 255.0 );                 // invert the y-axis while drawing                 glVertex2i( i % _width, _height - (i / _width) );             }         glEnd();     } } 

Any ideas as to the problem?

Edit: The problem was technically solved by starting a glutTimer from the openglThread which calls glutPostRedisplay() every 500ms. This is OK for now, but I would prefer a solution in which I only have to redisplay every time I make changes to the bitmap (to save on processing time) and one in which I don’t have to run another thread (the timer is another thread im assuming). This is mainly because the main processing thread is going to be doing a lot of intensive work and I would like to dedicate most of the resources to this thread rather than anything else.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:15:11+00:00Added an answer on May 11, 2026 at 4:15 am

    I’ve had this problem before – it’s pretty annoying. The problem is that all of your OpenGL calls must be done in the thread where you started the OpenGL context. So when you want your main (input) thread to change something in the OpenGL thread, you need to somehow signal to the thread that it needs to do stuff (set a flag or something).

    Note: I don’t know what your BitmapImage loading function (here, your constructor) does, but it probably has some OpenGL calls in it. The above applies to that too! So you’ll need to signal to the other thread to create a BitmapImage for you, or at least to do the OpenGL-related part of creating the bitmap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer https?://[^\?]+\?skw=([^%]*)(?:%2c\+*(.*))? In javascript this is var myregexp = /https?:\/\/[^\?]+(?:\?|\?[^&]*&)skw=([^%]*)(?:%2c\+*(.*))?/; var… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer RoutedCommands seem a bit misplaced in this case... you'll want… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer Right-click on the project, select 'Export...', then choose web ->… May 11, 2026 at 11:45 pm

Related Questions

I am going to be writing an application that does a bit of computation
I am working on an application that will have online and offline components and
In an application that I am currently working on, a requirement is to bring
In my VC++ application I have an embedded browser (MSHTML). It works fine and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.