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 6823189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:45:11+00:00 2026-05-26T21:45:11+00:00

I am a beginner at using openGL. I have used a program which I

  • 0

I am a beginner at using openGL.

I have used a program which I found over the internet to draw a cube on the screen and translate, scale and rotate it according to certain keyboard strokes.

Bellow, I have attached the code for doing this:

#define  RADDEG  57.29577951f

float XUP[3] = {1,0,0}, XUN[3] = {-1, 0, 0},
  YUP[3] = {0,1,0}, YUN[3] = { 0,-1, 0},
  ZUP[3] = {0,0,1}, ZUN[3] = { 0, 0,-1},
  ORG[3] = {0,0,0};

GLfloat viewangle = 0, tippangle = 0, traj[120][3];

GLfloat d[3] = {0.1, 0.1, 0.1};

GLfloat  xAngle = 0.0, yAngle = 0.0, zAngle = 0.0;

GLfloat scaleF = 0.2;


//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

//  Use arrow keys to rotate entire scene !!!

void Special_Keys (int key, int x, int y)
{
switch (key) {

   case GLUT_KEY_LEFT :  viewangle -= 5;  break;
   case GLUT_KEY_RIGHT:  viewangle += 5;  break;
   case GLUT_KEY_UP   :  tippangle -= 5;  break;
   case GLUT_KEY_DOWN :  tippangle += 5;  break;

   default: printf ("   Special key %c == %d\n", key, key);
}

glutPostRedisplay();
}

//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

void Keyboard (unsigned char key, int x, int y)
{
switch (key) {

   case 'j' : d[0] += 0.1;  break;
   case 'k' : d[0] -= 0.1;  break;
   case 'n' : d[1] += 0.1; break;
   case 'm' : d[1] -= 0.1; break;
   //case 'l' : d[2] += 0.1;  break;

   case 'z' : xAngle += 5;  break;
   case 'x' : yAngle += 5;  break;
   case 'c' : zAngle += 5;  break;

   case 'q' : scaleF += 0.1; break;
   case 'w' : scaleF -= 0.1; break;

   default: cout<< "Redo a valid keystroke;"<<endl;
}

glutPostRedisplay();
}

//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

void Triad (void)
{
glColor3f (1.0, 1.0, 1.0);

glBegin (GL_LINES);
   glVertex3fv (ORG); glVertex3fv (XUP);
   glVertex3fv (ORG); glVertex3fv (YUP);
   glVertex3fv (ORG); glVertex3fv (ZUP);
glEnd ();

glRasterPos3f (1.1, 0.0, 0.0);
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, 'X');

glRasterPos3f (0.0, 1.1, 0.0);
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, 'Y');

glRasterPos3f (0.0, 0.0, 1.1);
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, 'Z');
}

//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

void Draw_Box (void)
{
glBegin (GL_QUADS);

glColor3f(1,0,0);
    glVertex3f(1,1,1);
    glVertex3f(-1,1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(1,-1,1);

    glColor3f(0,1,1);
    glVertex3f(1,1,-1);
    glVertex3f(-1,1,-1);
    glVertex3f(-1,-1,-1);
    glVertex3f(1,-1,-1);

    glColor3f(0,1,0);
    glVertex3f(1,1,1);
    glVertex3f(1,-1,1);
    glVertex3f(1,-1,-1);
    glVertex3f(1,1,-1);

    glColor3f(1,0,1);
    glVertex3f(-1,1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(-1,-1,-1);
    glVertex3f(-1,1,-1);

    glColor3f(0,0,1);
    glVertex3f(1,1,1);
    glVertex3f(-1,1,1);
    glVertex3f(-1,1,-1);
    glVertex3f(1,1,-1);

    glColor3f(1,1,0);
    glVertex3f(1,-1,1);
    glVertex3f(-1,-1,1);
    glVertex3f(-1,-1,-1);
    glVertex3f(1,-1,-1);

glEnd();
}

//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

void redraw (void)
{
int v;

glClear  (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable (GL_DEPTH_TEST);

glLoadIdentity ();

glTranslatef (0, 0, -3);
glRotatef (tippangle, 1,0,0);  // Up and down arrow keys 'tip' view.
glRotatef (viewangle, 0,1,0);  // Right/left arrow keys 'turn' view.

glDisable (GL_LIGHTING);

Triad ();

glPushMatrix ();
   glTranslatef (d[0], d[1], d[2]);    // Move box down X axis.
   glScalef (scaleF, scaleF, scaleF);
   glRotatef (zAngle, 0,0,1);
   glRotatef (yAngle, 0,1,0);
   glRotatef (xAngle, 1,0,0);
   Draw_Box ();
glPopMatrix ();

glutSwapBuffers();
}

//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

void wait ( int seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
}

int main (int argc, char **argv)
{
glutInit               (&argc, argv);
glutInitWindowSize     (900, 600);
glutInitWindowPosition (300, 300);
glutInitDisplayMode    (GLUT_DEPTH | GLUT_DOUBLE);

glutCreateWindow ("Orbital Font Demo");
glutDisplayFunc  (   redraw   );
glutKeyboardFunc (  Keyboard  );
//glutSpecialFunc  (Special_Keys);



glClearColor (0.1, 0.0, 0.1, 1.0);

glMatrixMode   (GL_PROJECTION);
gluPerspective (60, 1.5, 1, 10);
glMatrixMode   (GL_MODELVIEW);
glutPostRedisplay();

glutMainLoop   ();



return 1;
}

//---+----3----+----2----+----1----+---<>---+----1----+----2----+----3----+----4

The thing is that I want to copy this code into another C++ program where I am using openCV libraries to connect my VGA camera. Based on the movements performed in front of the camera, I am classifying the performed movements using a SVM model.
I want to use the output of the SVM model which is basically a integer value and pass it to the openGL code in order to move the cube in the window.

In the above mentioned code, this procedure is performed by using keystrokes, and implicitly the glKeyboardFunc function. What functions should I use in order to connect the output of the SVM model to the redraw function of the above mentioned code?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T21:45:12+00:00Added an answer on May 26, 2026 at 9:45 pm

    You should use glutIdle to check whether there is a new frame. If there is you should update textures with new image using glTexSubImage2D*.

    *You should use a texture to display a custom image.

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

Sidebar

Related Questions

I am a beginner of Android apps and am using Eclipse. I have found
I am a beginner at using mysql/phpmyadmin, and have never used a cms before.
I am a beginner in iOS development and have just start using the lasted
I am a beginner in using Rails and Git I have InstantRails installed and
I am beginner at using JSP and am following a tutorial. I have a
i'm a beginner in PHP and i'm trying to make a login screen using
I am a beginner in using LINQ. I have an xml data with the
I have a beginner question using pointers in delphi. I create an object and
I am a beginner at C++ but I have some experience using Java. I
I am a beginner to using C# and MVC in general and I have

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.