# Thread: I need help for simple code

1. ## I need help for simple code

Hi everyone,

i need an OpenGL program that draws many colored objects in response to user input from keyboard.

The following objects are:

If the user input “l”, ot “L” à Draw Line, Color RED.
If the user input “t”, ot “T” à Draw Triangle, Color BLUE.
If the user input “p”, ot “P” à Draw a polyline, Color Orange, select its vertex by MOUSE (number of vertex = 6)

please help me as soon as you can , thank you ..

2. And what is your actual problem?

3. Originally Posted by d7om_5757
i need an OpenGL program that draws many colored objects in response to user input from keyboard.
Can you not write one yourself? Have you even tried to write one yourself? Nobody's going to write one for you, you know. You'll have to demonstrate that you're at least capable of being self-sufficient here.

4. yes , I have tried to write this code myself and this is what I wrote I need simple help I am a beginner

Code cpp:
```void myKeyboard(unsigned char theKey, int mouseX, int mouseY)
{
GLint x = mouseX;
GLint y = screenHeight - mouseY; // flip the y value as always
switch(theKey)
{
case ‘I’ or ‘L’:
drawLine(x1, y1, x2, y2);
setLine(x1, y1, x2, y2, 1.0, 0.0, 0.0);

break;

case ‘I’ or ‘L’:
float vertices[] = {
x1f,  y1f, // Vertex 1 (X, Y)
x2f,  y2f, // Vertex 2 (X, Y)
x3f,  y3f  // Vertex 3 (X, Y)
};

glUniform3f(uniColor, 1.0f, 0.0f, 0.0f);

break;

default:
break;
}
}```

Is it true or not and want code for number 3

thanks for help

5. Originally Posted by d7om_5757
yes , I have tried to write this code myself and this is what I wrote I need simple help I am a beginner

Code cpp:
```void myKeyboard(unsigned char theKey, int mouseX, int mouseY)
{
GLint x = mouseX;
GLint y = screenHeight - mouseY; // flip the y value as always
switch(theKey)
{
case ‘I’ or ‘L’:
drawLine(x1, y1, x2, y2);
setLine(x1, y1, x2, y2, 1.0, 0.0, 0.0);

break;

case ‘I’ or ‘L’:
float vertices[] = {
x1f,  y1f, // Vertex 1 (X, Y)
x2f,  y2f, // Vertex 2 (X, Y)
x3f,  y3f  // Vertex 3 (X, Y)
};

glUniform3f(uniColor, 1.0f, 0.0f, 0.0f);

break;

default:
break;
}
}```

Is it true or not and want code for number 3

thanks for help
So what happens when you try to run this code?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•