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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:14:11+00:00 2026-06-14T18:14:11+00:00

I’m learning OpenGL and I want to get a surface with a slight hump

  • 0

I’m learning OpenGL and I want to get a surface with a slight hump in the middle. I’m currently using this code and im not sure how to adjust the ctrl points to make it the way i want. Its currently like

enter image description here

and i would like to have it like this:

enter image description here

im not entirely sure what control points i should use and i’m confused on how it works.

#include <stdlib.h>
#include <GLUT/glut.h>

GLfloat ctrlpoints[4][4][3] = {
   {{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, 
    {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, 
   {{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, 
    {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, 
   {{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, 
    {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}}, 
   {{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, 
    {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}
};

void display(void)
{
   int i, j;

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glColor3f(1.0, 1.0, 1.0);
   glPushMatrix ();
   glRotatef(85.0, 1.0, 1.0, 1.0);
   for (j = 0; j <= 8; j++) {
      glBegin(GL_LINE_STRIP);
      for (i = 0; i <= 30; i++)
         glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);
      glEnd();
      glBegin(GL_LINE_STRIP);
      for (i = 0; i <= 30; i++)
         glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);
      glEnd();
   }
   glPopMatrix ();
   glFlush();
}

void init(void)
{
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
           0, 1, 12, 4, &ctrlpoints[0][0][0]);
   glEnable(GL_MAP2_VERTEX_3);
   glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
   glEnable(GL_DEPTH_TEST);
   glShadeModel(GL_FLAT);
}
void reshape(int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   if (w <= h)
      glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
               5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
   else
      glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
               5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (500, 500);
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutMainLoop();
   return 0;
}
  • 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-14T18:14:12+00:00Added an answer on June 14, 2026 at 6:14 pm

    EDIT: I thought you were experimenting, but I see the code came from the OpenGL tutorial. I glanced through it and understand your point now. It’s difficult to learn the basics from there.

    NURBS Background

    The best way to get a grasp with NURBS is to play with it interactively. You’d then gain the intuition about the edge-defining points (on the edges), shape defining ones (every other), the tangent-relation between them and continuity. NURBS can be made of patches, stitched together at the edges, where continuity is highly controlled – namely you can ask for G3 for car’s main body or C1 for a cheap game model. It’s really difficult to get the concept from any description. It you want to get it this way, I’d highly recommend the trial of Rhino Nurbs Modeller. I used it years ago and now it seems abandoned, but still it is the software with one of the best NURBS support out there (Autodesk 3d Studio MAX and MAYA have worse). It might be a little time consuming though, for starters I’d recommend playing with something simpler; take the applet from the “Simple Bezier Curve Editor” page for a spin.

    To understand NURBS it’s also good to consult Wikipedia Article about Bezier Curves. Once you get a grasp of relation between point position and the final curve shape you can easily generalize it to surfaces. I find this animation highly intuitive:

    Code Explanation

    You can imagine the surface from your example as a set of four of those curves, with a cloth spanned on them. Using the applet I linked earlier, you can play with the position and get instant feedback on the resulting shape. Notice the t parameter – it is a coordinate along the curve and has a range of [0, 1]. The NURBS surface have two of those coordinates, by convention called u and v (that’s important for the drawing function).

    So, the ctrlpoints structure from the code holds all point coordinates. Simplifying for explanation, those are four cubic Bezier curves (the ones from the animation). For each curve you have four points within 3 dimensions. If you disregard the Y-axis, then all of them lie on a grid, with X and Z being: -1.5, -1.0, 1.0, 1.5. That explains a total of 32 values (4×4 for X plus 4×4 for Z).

    The rest is the height, Y-values. In your case it is the second value of every point in ctrlpoints. To get your expected result, you can make all Y values equal on the edges (outer ones) and slightly raised in the middle (4 inner). You’ll get:

    NURBS Bump Surface

    Points used to render above image:

    GLfloat ctrlpoints[4][4][3] = {
     {{-1.5, 1.0, -1.5},  {-0.5, 1.0,-1.5 }, {0.5, 1.0, -1.5 },   {1.5, 1.0,-1.5}}, 
     {{-1.5, 1.0, -0.5},  {-0.5, 2.0,-0.5 }, {0.5, 2.0, -0.5 },   {1.5, 1.0,-0.5}}, 
     {{-1.5, 1.0,  0.5},  {-0.5, 2.0, 0.5 }, {0.5, 2.0,  0.5 },   {1.5, 1.0, 0.5}}, 
     {{-1.5, 1.0,  1.5},  {-0.5, 1.0, 1.5 }, {0.5, 1.0,  1.5 },   {1.5, 1.0, 1.5}}
    };
    //        ^                   ^                 ^                    ^
    //        |                   |                 |                    |
    //        |                   |                 |                    |
    //        \_________ Those are most relevant - Y-coord, height ______/
    

    NURBS in OpenGL with GLUT – API walkthrough

    I see OpenGL API is hiding quite relevant details. The NURBS surface is drawn using Evaluator and is defined with the Map function.

    You’re supposed to define control points in the init(void) function, like so:

    glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
               0, 1, 12, 4, &ctrlpoints[0][0][0]);
    

    Good explanation of the function can be found on the MSDN Site for glMap2f. We are passing control points, their type and the details such as array stride and order.

    You can draw it using an Evaluator function. It takes two coordinates as arguments and gives back a point in 3d space. Those input coordinates are exactly the u and v I mentioned earlier, under the animation. In our example:

          glBegin(GL_LINE_STRIP); // we'll draw a line
    
          // take 31 samples of a cross-section of the surface
          for (i = 0; i <= 30; i++)
             // for each sample, evaluate a 3d point
             glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);
    
             // notice j is constant in the loop here, but
             // is being changed by the outer loop.
             //
             // j is iterated in 9 steps, so we'll end up
             // with 9 lines
          glEnd();
    

    I deliberately omitted the outer loop, which is described here:

       // we want 9 lines
       for (j = 0; j <= 8; j++) {
          // OpenGL state machine will be used to draw lines
    
          glBegin(GL_LINE_STRIP);
          // inner loop for j-th line along X
    
          glBegin(GL_LINE_STRIP);
          // inner loop for j-th line along Z
    
          glEnd(); // done with the lines
       }
    

    Working example

    #include <stdlib.h>
    #include <GL/glut.h>
    
    GLfloat ctrlpoints[4][4][3] = {
     {{-1.5, 1.0, -1.5}, {-0.5, 1.0,-1.5 }, {0.5, 1.0, -1.5 }, {1.5, 1.0,-1.5}}, 
     {{-1.5, 1.0, -0.5}, {-0.5, 2.0,-0.5 }, {0.5, 2.0, -0.5 }, {1.5, 1.0,-0.5}}, 
     {{-1.5, 1.0,  0.5}, {-0.5, 2.0, 0.5 }, {0.5, 2.0,  0.5 }, {1.5, 1.0, 0.5}}, 
     {{-1.5, 1.0,  1.5}, {-0.5, 1.0, 1.5 }, {0.5, 1.0,  1.5 }, {1.5, 1.0, 1.5}}
    };
    
    void display(void)
    {
       int i, j;
    
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
       glColor3f(1.0, 1.0, 1.0);
       glPushMatrix();
       glRotatef(25.0, 1.0, 1.0, 1.0);
       for (j = 0; j <= 8; j++) {
          glBegin(GL_LINE_STRIP);
          for (i = 0; i <= 30; i++)
             glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);
          glEnd();
          glBegin(GL_LINE_STRIP);
          for (i = 0; i <= 30; i++)
             glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);
          glEnd();
       }
       glPopMatrix();
       glFlush();
    }
    
    void init(void)
    {
       glClearColor(0.0, 0.0, 0.0, 0.0);
       glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
               0, 1, 12, 4, &ctrlpoints[0][0][0]);
       glEnable(GL_MAP2_VERTEX_3);
       glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
       glEnable(GL_DEPTH_TEST);
       glShadeModel(GL_FLAT);
    }
    
    void reshape(int w, int h)
    {
       glViewport(0, 0, (GLsizei) w, (GLsizei) h);
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();
       if (w <= h)
          glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 
                   5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
       else
          glOrtho(-5.0*(GLfloat)w/(GLfloat)h, 
                   5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
    }
    
    int main(int argc, char** argv)
    {
       glutInit(&argc, argv);
       glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
       glutInitWindowSize(500, 500);
       glutInitWindowPosition(100, 100);
       glutCreateWindow(argv[0]);
       init();
       glutDisplayFunc(display);
       glutReshapeFunc(reshape);
       glutMainLoop();
       return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.