Click here to Skip to main content
15,843,145 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
the problem if am pressing 'a' key iwant point render in display screen but it is not work

why i dont know some body tell me about codeproject to solution this problem

C++
#include <stdio.h>
#include <stdlib.h>
 
#include <cmath>
#include <cstdlib>
#include <glut.h>
#include <iostream>
 
 
void createMenu(void);
void menu(int value);
float translateX = 0,translateY = 0;
static int win;
static int menyid;
static int transformation;
static int objectcolor;
static int Backgroundcolor;
static int val = 0;
GLsizei wh =720; 
GLsizei ww = 900 ;
bool  Point=false;
 
void drawLine()
 
{
      glPointSize(5);
          glTranslatef(translateX, translateY, 0);
          glColor3f(1.0,0.0,1.0);
          glLineWidth(6);
    glBegin(GL_LINES);
   glVertex2f(600.0,20.0);
   glVertex2f(30.0,20.0);
    glEnd();
    glFlush();
 
}   
 
void display(void)
{   
    glClearColor (1.0, 1.0, 1.0, 1.0);
    glClear (GL_COLOR_BUFFER_BIT);
    glLoadIdentity(); 
    drawLine(); // call function to draw line and Using ARROW UP,DOWN ,LEFT,RIGHT to move this Line 
 
  glPointSize(10);
 glColor3f(1.0,0.0,1.0);
 // Drawing Point 
 if(Point)
 {
 
           glPointSize(10);
 glColor3f(1.0,0.0,1.0);
 
    glBegin(GL_POINTS);
   glVertex2f(55.0,60.0);
    glEnd();
    glFlush();
 
 }
    glFlush();
}
 
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);
  gluOrtho2D ( 0.0, (GLdouble)ww, 0.0, (GLdouble)wh ); //Display area
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}
 
 
 void keypress (unsigned  char key, int x, int y)
{
    int modifiers = glutGetModifiers();
 
 
 
 
     switch (key) 
     {
       case 'a':
       case 27:
               Point=true;
               glutPostRedisplay();
               break;
     }
 
 
 
}
void specialfun(int k, int x, int y)
    {
    if (k == GLUT_KEY_LEFT)
        translateX -=1;// lef direction 
     else if (k == GLUT_KEY_RIGHT)//right direction 
        translateX +=1;
    else if (k == GLUT_KEY_UP)
        translateY +=1; // up direction 
    else if (k == GLUT_KEY_DOWN)
        translateY -=1; // down direction
     glutPostRedisplay();
}
 
void spindisplay(void)
{       
    glutPostRedisplay();
}
void createMenu(void){
    //////////
    // MENU //
    //////////
 
    // Create a submenu, this has to be done first.
    transformation = glutCreateMenu(menu);
 
    // Add sub menu entry
    glutAddMenuEntry("scaling", 1);
    glutAddMenuEntry("rotation", 2);
 
    objectcolor = glutCreateMenu(menu);
 
    glutAddMenuEntry("yellow", 3);
    glutAddMenuEntry("black", 4);
Backgroundcolor = glutCreateMenu(menu);
 
    glutAddMenuEntry("red", 3);
    glutAddMenuEntry("blue", 4);
    // Create the menu, this menu becomes the current menu
    menyid = glutCreateMenu(menu);
 
    // Create an entry
    glutAddSubMenu("Transformation", transformation);
    glutAddSubMenu("Object color", objectcolor);
    glutAddSubMenu("Background  color", Backgroundcolor);
    // Create an entry
    glutAddMenuEntry("Quit", 0);
 
    // Let the menu respond on the right mouse button
    glutAttachMenu(GLUT_RIGHT_BUTTON);
 
 
}
 
 
 void menu(int value){
    if(value == 0){
        exit(0);
        glutDestroyWindow(win);
 
    }else{
        val=value;
    }
 
    // you would want to redraw now
    glutPostRedisplay();
}
int main(int argc, char **argv)
{
 
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(800,768);
    glutInitWindowPosition(0,0);
    createMenu();
    glutCreateWindow("ASSIGNMENT2");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
 
        glutKeyboardFunc(keypress);
       glutSpecialFunc(specialfun);
    // ste the function to handle the updates for our program
 
     // Create our popup menu
createMenu();
  glutAttachMenu (GLUT_RIGHT_BUTTON);
 
    glutMainLoop();
 
}
Posted
Updated 1-Jun-13 10:49am
v3
Comments
beeko123 1-Jun-13 14:14pm    
the a key work
[no name] 1-Jun-13 15:01pm    
This is just an unformatted code dump. It is not a question or description of any kind of a problem.
beeko123 1-Jun-13 15:56pm    
if iam press 'a' iwant point showing in screen but it not work
iwill try use ascii code but it not work
iam a find in
void keypress (unsigned char key, int x, int y)
{
int modifiers = glutGetModifiers();




switch (key)
{
case 'a':
case 27:
Point=true;
glutPostRedisplay();
break;
}
how can solve this problem plz help me if u want more info tell
CPallini 1-Jun-13 15:23pm    
It looks you have also a communication problem.
Santhosh G_ 2-Jun-13 8:23am    
Please ensure 'a' is presssed and not 'A'.
Try to debug in keypress or log key parameter from keypress function.
Above code should display a point on pressing 'a' in keyboard.

1 solution

it not wok iam press but not work
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900