c++ - Draw triangle with glDrawArray function -


i want draw triangle in opengl gldrawarrays() function. following code: .cpp file:

        void linedr2::initializegl()    {             glclearcolor(0, 0, 0, 1.0);             glmatrixmode(gl_projection);             glloadidentity();             glortho(-10,10,-10,10,1,10);               vertices[0].x = 10;             vertices[0].y = 5;              // vertex 2            vertices[1].x = -10;            vertices[1].y = 3;                  // vertex 3           vertices[2].x = 5;          vertices[2].y = -5;         }      void linedr2::paintgl()      {               int num_indices = 2;              glenableclientstate( gl_vertex_array );                 glvertexpointer( 2, gl_float, 0, vertices);               gldrawarrays(gl_triangles, 0, num_indices);                gldisableclientstate( gl_vertex_array );            } 

.header file:

         #include <qwidget>          #include <qopenglwidget>          #include <gl/glu.h>          #include <gl/gl.h>           class linedr2: public qopenglwidget        {         public:          linedr2(qwidget *parent = 0);          ~linedr2();         struct vertex     {        glfloat x, y; //z;     };          vertex *vertices = new vertex[2];           protected:            void initializegl();          void paintgl();          void resizegl(int w, int h);          }; 

with code, getting blank window. no points getting plotted. doing wrong? there wrong in gldrawarray function?

i don't know happening when don't specify z component of vertices.

but 1 thing sure

glortho(-10,10,-10,10,1,10); 

will display belonging inside box. if z component 0 won't appear.

try replace like:

glortho(-10,10,-10,10,-1,10); 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -