home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / amiga / examples / mesatest.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  6KB  |  264 lines

  1. /* Discription:        */
  2. static char versionstring[]="\0$VER:       1.0 (dd-mm-yy)";
  3. #include <stdio.h>
  4. #define INTUI_V36_NAMES_ONLY
  5.  
  6. #include <exec/types.h>
  7. #include <exec/memory.h>
  8. #include <intuition/intuition.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/layers_protos.h>
  12. #include <clib/graphics_protos.h>
  13. #include <clib/intuition_protos.h>
  14.  
  15.  
  16. #include "qv:mesa/include/gl/AmigaMesa.h"
  17.  
  18. #define AMIGA
  19. #include <GL/gl.h>
  20. #include <GL/glu.h>
  21. #include <stdlib.h>
  22. #include "glaux.h"
  23.  
  24.  
  25. #ifdef LATTICE
  26. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  27. int chkabort(void) { return(0); }  /* really */
  28. #endif
  29.  
  30. struct Library *IntuitionBase;
  31. struct Library *GfxBase;
  32. struct Library *glBase;
  33. struct amigamesa_context *glcont;
  34.  
  35. #define IDCMPS IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_NEWSIZE
  36.  
  37.  
  38. void handle_window_events(struct Window *win);
  39. void rita(struct Window *win,struct RastPort *rport);
  40. void Init(void);
  41.  
  42.  
  43.  
  44. void Init(void)
  45. {
  46. /*    GLint i;*/
  47.  
  48. /*    glClearColor(0.0, 0.0, 0.0, 0.0);*/
  49.     glClearIndex(0);
  50.  
  51.     glMatrixMode (GL_PROJECTION);                /*  prepare for and then    */ 
  52.     glLoadIdentity ();                            /*  define the projection    */
  53.     glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);/*  transformation          */
  54.     glMatrixMode (GL_MODELVIEW);                /*  back to modelview matrix*/
  55.     glViewport (0, 0, 200, 200);                /*  define the viewport        */
  56.  
  57.     glShadeModel (GL_FLAT);
  58.  
  59.     glLoadIdentity ();    /*  clear the matrix    */
  60. /*    glTranslatef (0.0, 3.0, -5.0);*/    /*  viewing transformation    */
  61.     glTranslatef (0.0, 0.0, -5.0);    /*  viewing transformation    */
  62.     glScalef (2.0, 2.0, 2.0);    /*  modeling transformation    */
  63.  
  64. }
  65.  
  66.  
  67. void display (void)
  68. {
  69.     glClear(GL_COLOR_BUFFER_BIT);
  70.     glColor3f (1.0, 1.0, 1.0);
  71.  
  72.     glRotatef(1.0, 2.0,0,1);
  73.     auxWireCube(1.0);    /*  draw the cube    */
  74.     glFlush();
  75. /*    AmigaMesaSwapBuffers();*/
  76.  
  77. }
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. /*
  86. ** Open a simple window on the default public screen,
  87. ** then leave it open until the user selects the close gadget.
  88. */
  89. VOID main(int argc, char **argv)
  90. {
  91. struct Window *test_window = NULL;
  92. struct Screen *test_screen = NULL;
  93. if(glBase=OpenLibrary("gl.library",0))
  94. {
  95.  
  96. if (IntuitionBase = OpenLibrary("intuition.library",37))
  97.     {
  98.     if (GfxBase = OpenLibrary("graphics.library",37))
  99.         {                                    /* get a lock on the default public screen */
  100.         if (test_screen = LockPubScreen(NULL))
  101.             {
  102.                                         /* open the window on the public screen */
  103.  
  104.  
  105.             test_window = OpenWindowTags(NULL,
  106.                         WA_Left,  10,        WA_Top,    20,
  107.                         WA_InnerWidth, 200,    WA_InnerHeight, 200,
  108.                         WA_DragBar,         TRUE,
  109.                         WA_CloseGadget,     TRUE,
  110.                         WA_SizeGadget,        TRUE,
  111.                         WA_DepthGadget,        TRUE,
  112.                         WA_SmartRefresh,    TRUE,
  113.                         WA_ReportMouse,        TRUE,
  114.                         WA_NoCareRefresh,   TRUE,
  115.                         WA_SizeBBottom,        TRUE,
  116.                         WA_MinWidth,100,WA_MinHeight,14,
  117.                         WA_MaxWidth,-1,WA_MaxHeight,-1,
  118.                         WA_IDCMP,           IDCMPS,
  119.                         WA_Flags,            WFLG_SIZEGADGET | WFLG_DRAGBAR,
  120.                         WA_Title,           "MesaTest",
  121.                         WA_PubScreen,       test_screen,
  122.                         TAG_END);
  123.                                             /* Unlock the screen.  The window now acts as a lock on
  124.                                             ** the screen, and we do not need the screen after the
  125.                                             ** window has been closed.  */
  126.             UnlockPubScreen(NULL, test_screen);
  127.                                             /* if we have a valid window open, run the rest of the
  128.                                             ** program, then clean up when done. */
  129.  
  130.             if (test_window)
  131.                 {
  132.                 printf("Window is up\n");
  133.                 glcont=AmigaMesaCreateContext(test_window,GL_FALSE,GL_FALSE);
  134.                 if (glcont)
  135.                     {
  136.                     printf("Gl context created\n");
  137.                     AmigaMesaMakeCurrent(glcont);
  138.                     printf("Gl is up\n");
  139.  
  140.                     Init();
  141.                     printf("Init... Done\n");
  142.                     display();
  143.  
  144.  
  145.                     handle_window_events(test_window);
  146.                     AmigaMesaDestroyContext(glcont);
  147.                     }
  148.                 else
  149.                     {
  150.                     printf("GL Context faild\n");
  151.                     }
  152.                 CloseWindow(test_window);
  153.                 }
  154.             }
  155.         CloseLibrary(GfxBase);
  156.         }    
  157.     CloseLibrary(IntuitionBase);
  158.     }
  159. CloseLibrary(glBase);
  160. }
  161. }
  162.  
  163. /*  Wait for the user to select the close gadget. */
  164. void handle_window_events(struct Window *win)
  165. {
  166. struct IntuiMessage *msg;
  167. BOOL done = FALSE;
  168.  
  169. while (! done)
  170.     {
  171.                                 /* We have no other ports of signals to wait on,
  172.                                 ** so we'll just use WaitPort() instead of Wait()    */
  173. /*    WaitPort(win->UserPort);*/
  174.     display();
  175.  
  176.     while ( (! done) &&
  177.         (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  178.         {
  179.                                 /* use a switch statement if looking for multiple event types */
  180.         switch(msg->Class)
  181.             {
  182.             case    IDCMP_CLOSEWINDOW:
  183.                 done = TRUE;
  184.                 break;
  185.             case    IDCMP_NEWSIZE:
  186.                 glViewport (0, 0, win->Width-win->BorderLeft-win->BorderRight, win->Height-win->BorderTop-win->BorderBottom);    /*  define the viewport    */
  187.                 display();
  188.                 break;
  189.             }
  190.  
  191.         ReplyMsg((struct Message *)msg);
  192.         }
  193.     }
  194. }
  195.  
  196. #define    drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \
  197.     glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd();
  198.  
  199.  
  200. GLenum rgb, doubleBuffer, directRender, windType;
  201.  
  202.  
  203. GLenum mode1, mode2;
  204. GLint size;
  205. float pntA[3] = {
  206.     -160.0, 0.0, 0.0
  207. };
  208. float pntB[3] = {
  209.     -130.0, 0.0, 0.0
  210. };
  211. float pntC[3] = {
  212.     -40.0, -50.0, 0.0
  213. };
  214. float pntD[3] = {
  215.     30.0, 60.0, 0.0
  216. };
  217.  
  218.  
  219.  
  220.  
  221. void rita(struct Window *win,struct RastPort *rport)
  222.     {
  223. /*        SetABPenDrMd(rport,2,1,JAM1);
  224.         Move(rport,(win->BorderLeft),(win->BorderTop));
  225.         Draw(rport,win->BorderLeft+200,win->BorderTop+200);  */
  226.     
  227. /*    GLint i;*/
  228.  
  229. /*    glClear (GL_COLOR_BUFFER_BIT);*/
  230. /*  draw all lines in white    */
  231. /*    glColor3f (1.0, 1.0, 1.0);*/
  232.  
  233. /*  in 1st row, 3 lines drawn, each with a different stipple    */
  234. /*    glEnable (GL_LINE_STIPPLE);*/
  235. /*    glLineStipple (1, 0x0101);      dotted    */
  236.     drawOneLine (50.0, 125.0, 150.0, 125.0);
  237.     display();
  238. /*
  239.     for (i = 0; i < 360; i += 5)
  240.         {
  241.         glRotatef(5.0, 0,0,1);
  242.  
  243.         glIndexi(1);
  244.         
  245.         glBegin(GL_LINE_STRIP);
  246.             glVertex3fv(pntA);
  247.             glVertex3fv(pntB);
  248.         glEnd();
  249.  
  250.         glPointSize(1);
  251.  
  252.         glBegin(GL_POINTS);
  253.             glVertex3fv(pntA);
  254.             glVertex3fv(pntB);
  255.         glEnd();
  256.         }
  257. */
  258. /*
  259.       glPopMatrix();
  260.       glFlush();
  261. */
  262.     }
  263.     
  264.