Results 1 to 3 of 3

Thread: Display Lists

  1. #1
    Guest

    Display Lists

    Dear Reader,

    I am learning OpenGl with X windows. I have been trying to use display lists, but I do not get any thing on the screen. If I put the drawing code in the place where I call the list everything works.

    Could someone explain what I have done wrong.

    Here is the code.

    #include <stdio.h>
    #include <Xm/MainW.h>
    #include <Xm/Form.h>
    #include <Xm/DrawingA.h>
    #include <GL/gl.h>
    #include <GL/glu.h>
    #include <GL/glx.h>
    #include <GLwMDrawA.h>


    XVisualInfo *vi =NULL;
    GLXContext cx;
    Bool doubleBuffer = True;
    GLuint listname = 1;

    int BufferAttributes [] =
    {
    GLX_DOUBLEBUFFER,
    GLX_RGBA,
    GLX_DEPTH_SIZE, 12,
    GLX_RED_SIZE, 1,
    GLX_GREEN_SIZE, 1,
    GLX_BLUE_SIZE, 1,
    None
    };

    int *singleBufferAttributes = &BufferAttributes[0];
    int *doubleBufferAttributes = &BufferAttributes[1];

    void resize (Widget w, XtPointer clientdata, XtPointer calldata);
    void expose (Widget w, XtPointer clientdata, XtPointer calldata);
    void init (Widget w, XtPointer clientdata, XtPointer calldata);
    void draw (Widget w);

    int main (int argc, char **argv)
    {
    XtAppContext appContext;
    Display *display;
    Widget shell;
    Widget form;
    Widget draw;
    Arg args[10];
    int n;

    XtToolkitInitialize();

    appContext = XtCreateApplicationContext();

    display = XtOpenDisplay (appContext,NULL,"Test","Test",NULL,0,&argc,argv);

    if (vi == NULL)
    {
    vi = glXChooseVisual(display, DefaultScreen(display), doubleBufferAttribut
    es);
    if (vi == NULL)
    {
    vi = glXChooseVisual(display, DefaultScreen(display), singleBufferAttri
    butes);
    if (vi == NULL) XtAppError(appContext,"No RGB visual with depth buffer"
    );
    doubleBuffer = False;
    }
    }

    cx = glXCreateContext (display, vi, None, True);
    if (vi == NULL) XtAppError(appContext,"Could not create rendering context");

    n=0;
    XtSetArg(args[n], XmNallowShellResize, True); n++;
    XtSetArg(args[n], XmNtitle, "Main Window "); n++;
    shell = XtAppCreateShell("shell", "shell", applicationShellWidgetClass, displ
    ay, args, n);

    n=0;
    form = XtCreateWidget("form", xmFormWidgetClass, shell, args, n);
    XtManageChild (form);

    n=0;
    XtSetArg(args[n], XmNwidth, 400); n++;
    XtSetArg(args[n], XmNheight, 400); n++;
    XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], GLwNvisualInfo, vi); n++;

    draw = XtCreateWidget("Draw", glwMDrawingAreaWidgetClass, form, args,n);
    XtManageChild (draw);

    XtAddCallback(draw, GLwNexposeCallback, expose, NULL);
    XtAddCallback(draw, GLwNresizeCallback, resize, NULL);
    XtAddCallback(draw, GLwNginitCallback, init , NULL);

    XtRealizeWidget (shell);

    XtAppMainLoop(appContext);
    }

    float polygon1[3][3] = { {-10.0, -10.0, 0.0,},
    { 10.0, -10.0, 0.0,},
    {-10.0, 10.0, 0.0,} };

    float polygon2[3][3] = { { 0.0, -10.0, -10.0,},
    { 0.0, -10.0, 10.0,},
    { 0.0, 5.0, -10.0,} };

    float polygon3[4][3] = { {-10.0, 6.0, 4.0,},
    {-10.0, 3.0, 4.0,},
    { 4.0, -9.0, -10.0,},
    { 4.0, -6.0, -10.0,} };

    void init (Widget w, XtPointer clientdata, XtPointer calldata)
    {
    glNewList(listname,GL_COMPILE);
    glPushMatrix();
    glPushAttrib(GL_CURRENT_BIT);
    glBegin(GL_POLYGON);
    glColor3f(0.0, 0.0, 0.0);
    glVertex3fv(&polygon1[0][0]);
    glColor3f(0.7, 0.7, 0.7);
    glVertex3fv(&polygon1[1][0]);
    glColor3f(1.0, 1.0, 1.0);
    glVertex3fv(&polygon1[2][0]);
    glEnd();
    glBegin(GL_POLYGON);
    glColor3f(1.0, 1.0, 0.0);
    glVertex3fv(&polygon2[0][0]);
    glColor3f(0.0, 1.0, 0.7);
    glVertex3fv(&polygon2[1][0]);
    glColor3f(0.0, 0.0, 1.0);
    glVertex3fv(&polygon2[2][0]);
    glEnd();
    glBegin(GL_POLYGON);
    glColor3f(1.0, 1.0, 0.0);
    glVertex3fv(&polygon3[0][0]);
    glColor3f(1.0, 0.0, 1.0);
    glVertex3fv(&polygon3[1][0]);
    glColor3f(0.0, 0.0, 1.0);
    glVertex3fv(&polygon3[2][0]);
    glColor3f(1.0, 0.0, 1.0);
    glVertex3fv(&polygon3[3][0]);
    glEnd();
    glPopAttrib();
    glPopMatrix();
    glEndList ();
    }

    void expose (Widget w, XtPointer clientdata, XtPointer calldata)
    {
    glXMakeCurrent (XtDisplay(w), XtWindow(w), cx);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluPerspective(40.0, 1.0, 30.0, 1000.0);
    glTranslatef(0.0, 0.0, -40.0);
    glRotatef(-58.0, 0,1,0);

    glCallList (listname);

    glXSwapBuffers (XtDisplay(w), XtWindow(w));
    }


    void resize (Widget w, XtPointer clientdata, XtPointer calldata)
    {
    GLwDrawingAreaCallbackStruct *callbackData;
    callbackData = (GLwDrawingAreaCallbackStruct *) calldata;
    glXMakeCurrent(XtDisplay(w), XtWindow (w), cx);
    glXWaitX();
    glViewport (0,0,callbackData->width, callbackData->height);
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Sydney, NSW, Australia
    Posts
    426

    Re: Display Lists

    Hmmm, I didnt go through your code in detail, but I think you are placing the object in the same position as the camera, so maybe that is why you can see anything, put the object a few units into the z axis, sorry, but I dont have the time to go through the code in detail.
    :: Sleep is a poor substitute for caffeine ::

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Display Lists

    I'm not familiar with glx programming, but in Windows, you cannot use any OpenGL functions until the window is setup and enabled for OpenGL. If you try and create a display list before this initialization of the window, all the calls fail. Perhaps you are running into something similar.
    Deiussum
    Software Engineer and OpenGL enthusiast

Similar Threads

  1. cg & display lists
    By nib in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 11-04-2006, 07:22 PM
  2. Display Lists
    By azcoder in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-01-2002, 06:42 AM
  3. display lists inside display lists...
    By architekt in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-22-2002, 08:55 PM
  4. Display Lists
    By Robin Forster in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-14-2001, 06:11 PM
  5. display lists
    By frogger in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 07-27-2000, 10:03 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