Results 1 to 4 of 4

Thread: Vertex Arrays - help

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Grand Rapids, MI, USA
    Posts
    3

    Vertex Arrays - help

    I am reading the redbook, and am now learning Vertex arrays -
    whenever I declare glArrayElement()
    it messes up with some ESP error.
    I dont understand what I am doing wrong.
    I have a GLfloat array containing verticies for x and y values, and enabled GL_VERTEX_ARRAY, and have the glVertexPointer() with paramters 2, GL_FLOAT, 0, verticies.

    Please Help me

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Grand Rapids, MI, USA
    Posts
    3

    Re: Vertex Arrays - help

    here is all the code:

    #include <GL/glut.h>

    #define WS_X 600
    #define WS_Y 600
    #define WP_X 50
    #define WP_Y 50
    #define TITLE "OpenGL Pratice Program"

    void init(void);
    void display(void);
    void reshape(int w, int h);
    void keyboard(unsigned char key, int x, int y);

    int main(int argc, char** argv)
    {
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(WS_X,WS_Y);
    glutInitWindowPosition(WP_X,WP_Y);
    glutCreateWindow(TITLE);

    init();

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glutMainLoop();

    return 0;
    }

    void init(void)
    {
    gluOrtho2D (0.0, WS_X, 0.0, WS_Y);
    }

    void display(void)
    {
    static GLfloat verticies[] = {
    100.0, 25.0,
    100.0, 50.0,
    100.0, 60.0,
    125.0, 80.0};

    glClearColor(1.0,1.0,1.0,0.0);
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2,GL_FLOAT,0,verticies);
    glBegin(GL_TRIANGLES);
    glArrayElement(2);
    glArrayElement(3);
    glArrayElement(4);
    glEnd();
    glutSwapBuffers();
    }

    void reshape(int w, int h)
    {
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
    }

    void keyboard(unsigned char key, int x, int y)
    {
    switch(key)
    {
    case 27:
    exit(0);
    break;
    default:
    break;
    }
    }

  3. #3
    Member Contributor
    Join Date
    Mar 2002
    Location
    Figueira da Foz, Portugal
    Posts
    84

    Re: Vertex Arrays - help

    You're enabling GL_NORMAL_ARRAY without defining any normal array.

    Since you don't use lighting anyway, you'd be better off commenting out the line "glEnableClientState(GL_NORMAL_ARRAY)"

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2002
    Location
    Grand Rapids, MI, USA
    Posts
    3

    Re: Vertex Arrays - help

    that did the trick,
    thank you very much

Similar Threads

  1. arrays of arrays as vertex output/fragment input
    By tsojtsoj in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-17-2018, 08:02 PM
  2. Vertex Arrays, interleaved arrays, mouseMove func
    By Nibirue in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-13-2012, 11:17 AM
  3. Big problem show arrays with vertex arrays
    By Rondey in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 03-15-2009, 10:09 AM
  4. Vertex Arrays: Interleaved or seperated arrays?
    By Jan in forum OpenGL: Advanced Coding
    Replies: 16
    Last Post: 06-21-2005, 05:25 AM
  5. Vertex arrays and ... texture arrays
    By cix>foo in forum OpenGL: Advanced Coding
    Replies: 21
    Last Post: 06-25-2000, 08:15 AM

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