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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:27:24+00:00 2026-06-05T12:27:24+00:00

I am trying to change a C++ project, which is currently drawing some lines

  • 0

I am trying to change a C++ project, which is currently drawing some lines when I click on the view port. This functionality is perfectly fine, but what I am trying to change is when I click on “UP” or “Down” keys the color for next lines to change. Currently if I click on those keys the color changes for all the lines including the old ones (already drawn).

Please give me an idea of what to do. Here is some of the code:

void drawPrimitive() {
Vertex *temp;

//  Set the primitive color
glColor3fv(primitiveColor);

//  Set the point size in case we are drawing a point
if (type == POINT)
    glPointSize(pointSize);

//  Display results depending on the mode
glBegin(mode);
    for(temp = head; temp != NULL; temp = temp->np)
    {
        if (smoothShading)
            glColor3f(temp->r, temp->g, temp->b);

        glVertex2f(temp->x, temp->y);
    }
glEnd(); }


void mouse(int button, int state, int x, int y) {
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
    float pointX, pointY;

    pointX = (float)x/window_width * world_width;
    pointY = (float)(window_height - y)/window_height * world_height;

    //  Add a vertex to the list of vertices...
    addVertex(&head, &tail, pointX, pointY, 0.0f, primitiveColor[0], primitiveColor[1], primitiveColor[2]);

    //  automatically calls the display function
    glutPostRedisplay();
}
else if(button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
{
    deleteVertex(&head, &tail);
    glutPostRedisplay();
} }


void special(int key, int x, int y) {
switch (key)
{
    //  change primitive color
    case GLUT_KEY_UP :
        changePrimitiveColor(1);
        break;
    case GLUT_KEY_DOWN :
        changePrimitiveColor(-1);
        break;
}

glutPostRedisplay(); }


void changePrimitiveColor(int step) {
primitiveColorId += step;

if (primitiveColorId < 0)
    primitiveColorId = COLOR_COUNT - 1;

if (primitiveColorId >= COLOR_COUNT)
    primitiveColorId = 0;

setColor(primitiveColor, primitiveColorId); }
  • 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-06-05T12:27:25+00:00Added an answer on June 5, 2026 at 12:27 pm

    Your code is sort of unclear; is primitiveColor a global variable?

    Assuming you’re calling drawPrimitive() for all your lines each redraw, the same primitiveColor would be used for all the lines. As soon as you change the color when you press up or down, the redisplay function is called, and all the lines will be redrawn using the same color.

    What you might want to do is have a list containing both the primitives and their respective colors. When you iterate through this list, you can set a color for each line.

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

Sidebar

Related Questions

I'm trying to change a Button's Click property/event when a DataTrigger is triggered but
I'm trying to change the description of an existing SharePoint group which shouldn't be
I'm trying to change the content of a ContentPresenter to one of my View
this is my first post, and it covers something which I've been trying to
I'm working on a project that requires that the vertical borders, which are currently
I am currently working on a project which allows users to design a small
I'm currently working on an inherited project which uses Google's Visualization API (for both
I'm currently working on a project which is nearly done, but there's one more
I'm trying change an input mask for textbox when the the check box has
I´m trying to change a spring jsp example to use freemarker. I changed all

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.