Results 1 to 3 of 3

Thread: Help with glDrawElements

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    17

    Help with glDrawElements

    Hi, I am new to openGL, and trying to generate triangular mesh
    using glDrawElements().

    Currently my code just tries to display one triangle using the
    glDrawElemsnts().

    I ran the program using glBegin(GL_TRIANGLES), it works fine,

    but when I use glDrawElemnts(), I cant see anything on screen.

    Please Help!!.




    #ifdef _WIN32
    #include <GL/freeglut.h>
    #else
    #include <GL/glut.h>
    #endif


    #include <windows.h>
    #include <iostream>

    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    #include <ctime>

    #include "glext.h"

    using namespace std;





    GLint vertices[] = { 10,20,
    300,400,
    10,260};

    GLuint indices[] = {1,2,3};




    void display(void)
    {


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glColor3f(0,1,0);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3,GL_INT,0,vertices);
    glDrawElements(GL_TRIANGLES,3,GL_UNSIGNED_INT,indi ces);
    glDisableClientState(GL_VERTEX_ARRAY);
    glutSwapBuffers();
    }//EOF



    void reshape(int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, (GLdouble)w, 0, (GLdouble)h, -5.0, 5.0);
    glMatrixMode(GL_MODELVIEW);

    }
    int main(int argc, char** argv)
    {
    glutInit(&amp;argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE |GLUT_RGB | GLUT_DEPTH );
    glEnable(GL_DEPTH_TEST);

    glutInitWindowSize(500,500);
    glutInitWindowPosition( 200,200);
    glutCreateWindow("Hello_World");
    glClearColor(0.0,0.0,0.0,0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutIdleFunc(display);
    // glutPassiveMotionFunc(&amp;mouse_move);



    glutMainLoop();

    return 0;
    }

    //EOF

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675

    Re: Help with glDrawElements

    GLuint indices[] = {1,2,3};
    Zero base indices.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    17

    Re: Help with glDrawElements

    ok, solves the problem,
    thanks..

Similar Threads

  1. about glDrawElements
    By freesui1984 in forum OpenGL ES
    Replies: 3
    Last Post: 10-10-2008, 04:17 AM
  2. Getting glDrawElements
    By Cribs in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-24-2007, 09:46 PM
  3. glDrawElements
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-28-2005, 04:39 AM
  4. Once & Again: glDrawElements
    By t33mu in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 06-02-2001, 09:16 AM
  5. glDrawElements()
    By eckiller in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-04-2000, 11:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean