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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:01:26+00:00 2026-06-10T03:01:26+00:00

In my rendering loop I have the following logic. I have other things render

  • 0

In my rendering loop I have the following logic. I have other things render to the screen, and they render, (I removed that code to get right to the point). This code does not render a sphere, and I can’t figure out why not. Am I missing something in the math? I have stepped through with the debugger and the values seem right. Note mBubbleDiameter is 20 as set in the constructor of this object.

static GLfloat staticDegreesToRadians(GLfloat tmpDegrees) {
    return tmpDegrees * ((std::atan(1.0f)*4)/180.0f);
}

void LedPannelWidget::updateGL() {
    glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        glViewport(0, 0, mWidth, mHeight);
        glOrtho(0, mWidth, 0, mHeight, -mBubbleDiameter, mBubbleDiameter);

    glMatrixMode(GL_MODELVIEW);
        glScissor(0, 0, mWidth, mHeight);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClearColor(0.92f, 0.92f, 0.92f, 1.0);

        glLoadIdentity();
    const GLfloat tmpRadius = mDiameter/2.0f;
    const GLfloat tmpDelta = 5.00f;
    const GLfloat tmpDeltaRadians = staticDegreesToRadians(tmpDelta);

    for (int32_t tmpTheta = 180; tmpTheta > 0; tmpTheta -= tmpDelta) {
        for (int32_t tmpPhi = 0; tmpPhi < 360; tmpPhi += tmpDelta) {
            GLfloat tmpThetaRadians = staticDegreesToRadians(tmpTheta);
            GLfloat tmpPhiRadians = staticDegreesToRadians(tmpTheta);

            GLfloat tmpX1 = tmpRadius *
                std::sin(tmpThetaRadians) * 
                std::cos(tmpPhiRadians); 
            GLfloat tmpY1 = tmpRadius *
                std::sin(tmpThetaRadians) *
                std::cos(tmpPhiRadians);
            GLfloat tmpZ1 = tmpRadius *
                std::cos(tmpThetaRadians);

            GLfloat tmpX2 = tmpRadius *
                std::sin(tmpThetaRadians - tmpDeltaRadians) * 
                std::cos(tmpPhiRadians);
            GLfloat tmpY2 = tmpRadius *
                std::sin(tmpThetaRadians - tmpDeltaRadians) *
                std::cos(tmpPhiRadians); 
            GLfloat tmpZ2 = tmpRadius *
                std::cos(tmpThetaRadians - tmpDeltaRadians);

            GLfloat tmpX3 = tmpRadius * 
                std::sin(tmpThetaRadians - tmpDeltaRadians) *
                std::cos(tmpPhiRadians + tmpDeltaRadians);
            GLfloat tmpY3 = tmpRadius *
                std::sin(tmpThetaRadians - tmpDeltaRadians) *
                std::cos(tmpPhiRadians + tmpDeltaRadians);
            GLfloat tmpZ3 = tmpRadius *
                std::cos(tmpThetaRadians - tmpDeltaRadians);

            GLfloat tmpX4 = tmpRadius *  
                std::sin(tmpThetaRadians) *
                std::cos(tmpPhiRadians + tmpDeltaRadians);

            GLfloat tmpY4 = tmpRadius *
                std::sin(tmpThetaRadians) *
                std::cos(tmpPhiRadians + tmpDeltaRadians);

            GLfloat tmpZ4 = tmpRadius *
                std::cos(tmpThetaRadians);

            glBegin(GL_QUADS);
                glVertex3f(tmpX1, tmpY1, tmpZ1);
                glVertex3f(tmpX2, tmpY2, tmpZ2);
                glVertex3f(tmpX3, tmpY3, tmpZ3);
                glVertex3f(tmpX4, tmpY4, tmpZ4);
            glEnd();

            if (tmpGLError != GL_NO_ERROR) {
                QApplication::exit(0);
            }
        }
    }
    swapBuffers();
}

Working GL Algorithm:

const GLfloat r = mDiameter/2.0f;
const GLfloat phid = 20.00f;
const GLfloat thetad = 20.00f;
const GLfloat x = mCenterXCoord;
const GLfloat y = mCenterYCoord;

using namespace std;
for (int32_t phi = 180; phi > 0; phi -= phid) {
    int32_t theta = 0;
    GLfloat rphi = staticDegreesToRadians(phi);
    GLfloat rtheta = staticDegreesToRadians(theta);
    glBegin(GL_QUAD_STRIP);
    glColor3f(mCurrentColor.red()/255.0, mCurrentColor.green()/255.0,
        mCurrentColor.blue()/255.0);
    glVertex3f(
        (x + (r * sin(rphi) * cos(rtheta))),
        (y + (r * cos(rphi))),
        (0 + (r * sin(rphi) * cos(rtheta))));
    glVertex3f(
        (x + (r * sin(rphi + phid) * cos(rtheta))),
        (y + (r * cos(rphi + phid))),
        (0 + (r * sin(rphi + phid) * cos(rtheta))));

    for (; theta < 360; theta += thetad) {
        rtheta = staticDegreesToRadians(theta);
        glVertex3f(
            (x + (r * sin(rphi + phid) * cos(rtheta + thetad))),
            (y + (r * cos(rphi + phid))),
            (0 + (r * sin(rphi + phid) * cos(rtheta + thetad))));
        glVertex3f(
            (x + (r * sin(rphi) * cos(rtheta + thetad))),
            (y + (r * cos(rphi))),
            (0 + (r * sin(rphi) * cos(rtheta + thetad))));
    }
    glEnd();
}
  • 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-10T03:01:28+00:00Added an answer on June 10, 2026 at 3:01 am

    Check your code in these lines

           GLfloat tmpThetaRadians = staticDegreesToRadians(tmpTheta);
            GLfloat tmpPhiRadians = staticDegreesToRadians(tmpTheta);
    
            GLfloat tmpX1 = tmpRadius *
                std::sin(tmpThetaRadians) * 
                std::cos(tmpPhiRadians); 
            GLfloat tmpY1 = tmpRadius *
                std::sin(tmpThetaRadians) *
                std::cos(tmpPhiRadians);
            GLfloat tmpZ1 = tmpRadius *
                std::cos(tmpThetaRadians);
    

    You need changes see below

           GLfloat tmpThetaRadians = staticDegreesToRadians(tmpTheta);
           GLfloat tmpPhiRadians = staticDegreesToRadians(tmpPhi);
           GLfloat tmpX1 = tmpRadius *
                std::sin(tmpThetaRadians) * 
                std::sin(tmpPhiRadians); 
            GLfloat tmpY1 = tmpRadius *
                std::sin(tmpThetaRadians) *
                std::cos(tmpPhiRadians);
            GLfloat tmpZ1 = tmpRadius *
                std::cos(tmpThetaRadians);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is for a Terrain Generation and rendering program. I have a loop that
I have written following simple code to see the behavior of rendering. In this
Does anyone know or have good links that explain what iPhone's event loop does
so I have a file that will get $_GET['id'] from an ajax request here
I have read about using CompositionTarget.Rendering Timer for the primary gaming loop in silverlight.
I have seen the game Airplane Madness rendering the screen at a constant average
I have a small app that has a Render thread. All this thread does
Right now, I have a do loop for a task model in my view:
Scenario: I have a partial view that is used in several places across my
I have a very fast loop which renders animation in a Bitmap buffer and

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.