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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:57:03+00:00 2026-05-26T15:57:03+00:00

how to rotate a single triangle that drawn on the screen managed to rotate

  • 0

how to rotate a single triangle that drawn on the screen managed to rotate everything on the screen. the code below rotates all the drawings i just want to rotate one drawing.

void SpecialKeys(int key, int x, int y)
{

    if(key == GLUT_KEY_UP)
        glRotatef(10,0.0,0.0,1.0);

    if(key == GLUT_KEY_DOWN)
        glRotatef(10,0.0,0.0,-1.0);

    // Refresh the Window
    glutPostRedisplay();
}
  • 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-26T15:57:03+00:00Added an answer on May 26, 2026 at 3:57 pm

    In the input handler set variables, apply transformations in the drawing function.

    OpenGL is not a scene graph. This means that you’re not building some scene representation in OpenGL, that you could alter later. OpenGL is a drawing API. It gives you the digital equivalent of pencils, brushes, collages to draw on a canvas provided by the operating system.

    This also means, that when you change something in the scene, you redraw the things from scratch.

    Due to this working of OpenGL is makes no sense to do matrix manipulations, or actually any kind of OpenGL operation at all in a input event handler. It simply doesn’t work that way.

    Update

    Minimal GLUT user interaction code sample (OpenGL-1.1):

    #include <math.h>
    #include <GL/gl.h>
    #include <GL/glut.h>
    
    struct {
        float triangle_rotation;
    } scene;
    
    static const GLfloat triangle_vertices[3][3] = {
        {-1., -1., 0.},
        { 1., -1., 0.},
        { 0., 0.732, 0.}
    };
    
    static void draw_triangle()
    {
        glEnableClientState(GL_VERTEX_ARRAY);
        glVertexPointer(3, GL_FLOAT, 3*sizeof(GLfloat), &triangle_vertices[0][0]);
        glDrawArrays(GL_TRIANGLES, 0, 3);
        glDisableClientState(GL_VERTEX_ARRAY);
    }
    
    static void display(void)
    {
        const int window_width = glutGet(GLUT_WINDOW_WIDTH);
        const int window_height = glutGet(GLUT_WINDOW_HEIGHT);
        if( !window_width || !window_height )
            return;
        const float window_aspect = (float)window_width / (float)window_height;
    
        glDisable(GL_SCISSOR_TEST);
    
        glClearColor(0.4, 0.3, 0.5, 1.0);
        glClearDepth(1.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glViewport(0, 0, window_width, window_height);
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glFrustum(-window_aspect, window_aspect, -1, 1, 2, 10);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(0., 0., -5.);
    
        glPushMatrix();
        glRotatef(scene.triangle_rotation, 0., 1., 0.);
        draw_triangle();
        glPopMatrix();
    
        glutSwapBuffers();
    }
    
    static void special_key(int key, int x, int y)
    {
        switch(key) {
        case GLUT_KEY_LEFT:
            scene.triangle_rotation = fmod(scene.triangle_rotation + 5, 360);
            break;
        case GLUT_KEY_RIGHT:
            scene.triangle_rotation = fmod(scene.triangle_rotation - 5, 360);
            break;
        default:
            break;
        }
        glutPostRedisplay();
    }
    
    int main(int argc, char *argv[])
    {
        glutInit(&argc, argv);
    
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
        glutCreateWindow("Simple input altering scene demo");
        glutDisplayFunc(display);
        glutSpecialFunc(special_key);
    
        glutMainLoop();
    }
    

    On Github

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

Sidebar

Related Questions

Hello All I want to rotate UIView on single finger touch and it still
I want to rotate a single word of text by 90 degrees, with cross-browser
I want to display and rotate a single 3D model, preferably textured, on the
I have a set of 3D coordinates (below - just for a single point,
I have a map drawn in SVG that I use matrix transformations to rotate
I'm trying to figure out how to rotate a single object on an html
I have a jQuery script that creates a carousel to rotate images left and
I'm trying to scale and rotate in single operation before creting the final bitmap
in this code i'm try to draw simple olympic ring and rotate it... the
I'm trying to rotate an image by just touch and move. Here is my

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.