int
main(int argc, char *argv[])
{
   Display *dpy;
   Window win;
   GLXContext ctx;
   char *dpyName = NULL;
   int swap_interval = 1;
   GLboolean do_swap_interval = GL_FALSE;
   GLboolean force_get_rate = GL_FALSE;
   GLboolean fullscreen = GL_FALSE;
   GLboolean printInfo = GL_FALSE;
   int i;
   PFNGLXSWAPINTERVALMESAPROC set_swap_interval = NULL;
   PFNGLXGETSWAPINTERVALMESAPROC get_swap_interval = NULL;
   int width = 300, height = 300;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
         dpyName = argv[i+1];
         i++;
      }
      else if (strcmp(argv[i], "-info") == 0) {
         printInfo = GL_TRUE;
      }
      else if (strcmp(argv[i], "-swap") == 0 && i + 1 < argc) {
	 swap_interval = atoi( argv[i+1] );
	 do_swap_interval = GL_TRUE;
	 i++;
      }
      else if (strcmp(argv[i], "-forcegetrate") == 0) {
	 /* This option was put in because some DRI drivers don't support the
	  * full GLX_OML_sync_control extension, but they do support
	  * glXGetMscRateOML.
	  */
	 force_get_rate = GL_TRUE;
      }
      else if (strcmp(argv[i], "-fullscreen") == 0) {
         fullscreen = GL_TRUE;
      }
      else if (strcmp(argv[i], "-ztrick") == 0) {
	 use_ztrick = GL_TRUE;
      }
      else if (strcmp(argv[i], "-help") == 0) {
         printf("Usage:\n");
         printf("  gears [options]\n");
         printf("Options:\n");
         printf("  -help                   Print this information\n");
         printf("  -display displayName    Specify X display\n");
         printf("  -info                   Display GL information\n");
         printf("  -swap N                 Swap no more than once per N vertical refreshes\n");
         printf("  -forcegetrate           Try to use glXGetMscRateOML function\n");
         printf("  -fullscreen             Full-screen window\n");
         return 0;
      }
   }

   dpy = XOpenDisplay(dpyName);
   if (!dpy) {
      printf("Error: couldn't open display %s\n", XDisplayName(dpyName));
      return -1;
   }

   make_window(dpy, "glxgears", 0, 0, width, height, fullscreen, &win, &ctx);
   XMapWindow(dpy, win);
   glXMakeCurrent(dpy, win, ctx);

   make_extension_table( (char *) glXQueryExtensionsString(dpy,DefaultScreen(dpy)) );
   has_OML_sync_control = is_extension_supported( "GLX_OML_sync_control" );
   has_SGI_swap_control = is_extension_supported( "GLX_SGI_swap_control" );
   has_MESA_swap_control = is_extension_supported( "GLX_MESA_swap_control" );
   has_MESA_swap_frame_usage = is_extension_supported( "GLX_MESA_swap_frame_usage" );

   if ( has_MESA_swap_control ) {
      set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalMESA" );
      get_swap_interval = (PFNGLXGETSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXGetSwapIntervalMESA" );
   }
   else if ( has_SGI_swap_control ) {
      set_swap_interval = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB( (const GLubyte *) "glXSwapIntervalSGI" );
   }


   if ( has_MESA_swap_frame_usage ) {
      get_frame_usage = (PFNGLXGETFRAMEUSAGEMESAPROC)  glXGetProcAddressARB( (const GLubyte *) "glXGetFrameUsageMESA" );
   }
      

   if (printInfo) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
      if ( has_OML_sync_control || force_get_rate ) {
	 show_refresh_rate( dpy );
      }

      if ( get_swap_interval != NULL ) {
	 printf("Default swap interval = %d\n", (*get_swap_interval)() );
      }
   }

   if ( do_swap_interval ) {
      if ( set_swap_interval != NULL ) {
	 if ( ((swap_interval == 0) && !has_MESA_swap_control)
	      || (swap_interval < 0) ) {
	    printf( "Swap interval must be non-negative or greater than zero "
		    "if GLX_MESA_swap_control is not supported.\n" );
	 }
	 else {
	    (*set_swap_interval)( swap_interval );
	 }

	 if ( printInfo && (get_swap_interval != NULL) ) {
	    printf("Current swap interval = %d\n", (*get_swap_interval)() );
	 }
      }
      else {
	 printf("Unable to set swap-interval.  Neither GLX_SGI_swap_control "
		"nor GLX_MESA_swap_control are supported.\n" );
      }
   }

   init();

   /* Set initial projection/viewing transformation.
    * same as glxgears.c
    */
   reshape(width, height);

   event_loop(dpy, win);

   glXDestroyContext(dpy, ctx);
   XDestroyWindow(dpy, win);
   XCloseDisplay(dpy);

   return 0;
}
Exemple #2
0
int
main(int argc, char *argv[])
{
   unsigned int winWidth = 300, winHeight = 300;
   int x = 0, y = 0;
   Display *dpy;
   Window win;
   GLXContext ctx;
   char *dpyName = NULL;
   GLboolean printInfo = GL_FALSE;
   int i;

   for (i = 1; i < argc; i++) {
      if (strcmp(argv[i], "-display") == 0) {
         dpyName = argv[i+1];
         i++;
      }
      else if (strcmp(argv[i], "-info") == 0) {
         printInfo = GL_TRUE;
      }
      else if (strcmp(argv[i], "-stereo") == 0) {
         stereo = GL_TRUE;
      }
      else if (i < argc-1 && strcmp(argv[i], "-samples") == 0) {
         samples = strtod(argv[i+1], NULL );
         ++i;
      }
      else if (strcmp(argv[i], "-fullscreen") == 0) {
         fullscreen = GL_TRUE;
      }
      else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
         XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
         i++;
      }
      else if (i < argc-1 && strcmp(argv[i], "-visualid") == 0) {
         sscanf(argv[i+1], "%x", &visualid);
         i++;
      }
      else if (i < argc-1 && strcmp(argv[i], "-interval") == 0) {
         int temp = -1;
         sscanf(argv[i+1], "%d", &temp);
         if (temp >= 1) swapinterval = temp;
         i++;
      }
      else {
         usage();
         return -1;
      }
   }

   dpy = XOpenDisplay(dpyName);
   if (!dpy) {
      printf("Error: couldn't open display %s\n",
	     dpyName ? dpyName : getenv("DISPLAY"));
      return -1;
   }

   if (fullscreen) {
      int scrnum = DefaultScreen(dpy);

      x = 0; y = 0;
      winWidth = DisplayWidth(dpy, scrnum);
      winHeight = DisplayHeight(dpy, scrnum);
   }

   make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx);
   XMapWindow(dpy, win);
   glXMakeCurrent(dpy, win, ctx);
   query_vsync(dpy, win);

   if (printInfo) {
      printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
      printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
      printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
      printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
   }

   init();

   /* Set initial projection/viewing transformation.
    * We can't be sure we'll get a ConfigureNotify event when the window
    * first appears.
    */
   reshape(winWidth, winHeight);

   event_loop(dpy, win);

   glDeleteLists(gear1, 1);
   glDeleteLists(gear2, 1);
   glDeleteLists(gear3, 1);
   glXMakeCurrent(dpy, None, NULL);
   glXDestroyContext(dpy, ctx);
   XDestroyWindow(dpy, win);
   XCloseDisplay(dpy);

   return 0;
}
Exemple #3
0
int two_choice(char *choice1, char *choice2, char *string, char *key, int x,
               int y, Window w, char *title) {
  Window base, c1, c2, wm;
  XEvent ev;
  int not_done = 1;
  int value = 0;
  int l1 = strlen(choice1) * DCURX;
  int l2 = strlen(choice2) * DCURX;
  int lm = strlen(string) * DCURX;
  int tot = lm, xm, x1, x2;

  if (lm < (l1 + l2 + 4 * DCURX))
    tot = (l1 + l2 + 4 * DCURX);
  tot = tot + 6 * DCURX;
  xm = (tot - lm) / 2;
  x1 = (tot - l1 - l2 - 4 * DCURX) / 2;
  x2 = x1 + l1 + 4 * DCURX;
  base = make_plain_window(w, x, y, tot, 5 * DCURY, 4);

  make_icon((char *)alert_bits, alert_width, alert_height, base);

  c1 = make_window(base, x1, 3 * DCURY, l1 + DCURX, DCURY + 4, 1);
  c2 = make_window(base, x2, 3 * DCURY, l2 + DCURX, DCURY + 4, 1);
  XSelectInput(display, c1, BUT_MASK);
  XSelectInput(display, c2, BUT_MASK);

  wm = make_window(base, xm, DCURY / 2, lm + 2, DCURY, 0);

  ping();
  if (w == RootWindow(display, screen)) {
    if (title == NULL) {
      set_window_title(base, "!!!!");
    } else {
      set_window_title(base, title);
    }
  }

  while (not_done) {
    XNextEvent(display, &ev);
    switch (ev.type) {
    case Expose:
    case MapNotify:
      do_expose(ev);
      expose_choice(choice1, choice2, string, c1, c2, wm, ev.xexpose.window);
      break;

    case ButtonPress:
      if (ev.xbutton.window == c1) {
        value = (int)key[0];
        not_done = 0;
      }
      if (ev.xbutton.window == c2) {
        value = (int)key[1];
        not_done = 0;
      }
      break;
    case KeyPress:
      value = get_key_press(&ev);
      not_done = 0;
      break;
    case EnterNotify:
      if (ev.xcrossing.window == c1 || ev.xcrossing.window == c2)
        XSetWindowBorderWidth(display, ev.xcrossing.window, 2);
      XFlush(display);
      break;
    case LeaveNotify:
      if (ev.xcrossing.window == c1 || ev.xcrossing.window == c2)
        XSetWindowBorderWidth(display, ev.xcrossing.window, 1);
      XFlush(display);
      break;
    }
  }
  waitasec(2 * ClickTime);
  XFlush(display);
  XSelectInput(display, c1, EV_MASK);
  XSelectInput(display, c2, EV_MASK);
  XFlush(display);
  XDestroySubwindows(display, base);
  XDestroyWindow(display, base);
  return (value);
}
int main(int argc, char **argv) 
{
  // Initialize form, sliders and buttons
  form = make_window();

  performanceCounter.StartCounter();  // init
  saveFileTimeCounter.StartCounter(); // init

  groundPlane_button->value(groundPlane);
  fog_button->value(useFog);
  worldAxes_button->value(renderWorldAxes);
  frame_slider->value(1);
  if (saveScreenToFile == SAVE_CONTINUOUS)
    record_button->value(1);  // ON
  else
    record_button->value(0);  // OFF

  // just do some timing, no special purpose
  // because the first data is always not trustable according to experience
  performanceCounter.StopCounter(); 
  performanceCounter.GetElapsedTime();
  saveFileTimeCounter.StopCounter();
  saveFileTimeCounter.GetElapsedTime();
  performanceCounter.StartCounter();
  // show form, and do initial draw of model
  form->show();
  glwindow->show(); // glwindow is initialized when the form is built
  performanceCounter.StopCounter();

  if (argc > 2)
  {
    char *filename;

    filename = argv[1];
    if(filename != NULL)
    {
      //Read skeleton from asf file
      pSkeleton = new Skeleton(filename, MOCAP_SCALE);

      //Set the rotations for all bones in their local coordinate system to 0
      //Set root position to (0, 0, 0)
      pSkeleton->setBasePosture();
      displayer.LoadSkeleton(pSkeleton);
      lastSkeleton++;
    }

    if (displayer.GetNumSkeletons())
    {
      filename = argv[2];
      if(filename != NULL)
      {
        //Read motion (.amc) file and create a motion
        pMotion = new Motion(filename, MOCAP_SCALE,pSkeleton);

        //set sampled motion for display
        displayer.LoadMotion(pMotion);               
        
        lastMotion++;

        //Tell skeleton to perform the first pose ( first posture )
        pSkeleton->setPosture(*(displayer.GetSkeletonMotion(0)->GetPosture(0)));          

        // Set skeleton to perform the first pose ( first posture )         
        int currentFrames = displayer.GetSkeletonMotion(0)->GetNumFrames();
        if (currentFrames > maxFrames)
        {
          maxFrames = currentFrames;
          frame_slider->maximum((double)maxFrames);

        }
        frame_slider->maximum((double)maxFrames);

        currentFrameIndex=0;
      } // if(filename != NULL)
    }
    else
      printf("Load a skeleton first.\n");
    framesIncrementDoublePrecision = 1.0;            // Current frame and frame increment
    playButton = ON;
    repeatButton = OFF;
    groundPlane = ON; 
    glwindow->redraw();
  }  // if (argc > 2)
  Fl::add_idle(idle);
  return Fl::run();
}
Exemple #5
0
/* www_process():
 *
 * The program's signal dispatcher function. Is called whenever a signal arrives.
 */
PROCESS_THREAD(www_process, ev, data)
{
  static struct ctk_widget *w;
  static unsigned char i;
#if WWW_CONF_WITH_WGET
  static char *argptr;
#endif /* WWW_CONF_WITH_WGET */

  w = (struct ctk_widget *)data;

  PROCESS_BEGIN();
  
  /* Create the main window. */
  memset(webpage, 0, sizeof(webpage));
  ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH,
		 WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser");
  make_window();
#ifdef WWW_CONF_HOMEPAGE
  strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl));
#endif /* WWW_CONF_HOMEPAGE */
  CTK_WIDGET_FOCUS(&mainwindow, &urlentry);
  
#if WWW_CONF_WITH_WGET
  /* Create download dialog.*/
  ctk_dialog_new(&wgetdialog, 38, 7);
  CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1);
  CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2);
  CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton);
  CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton);
#endif /* WWW_CONF_WITH_WGET */

  ctk_window_open(&mainwindow);
  
  while(1) {

    PROCESS_WAIT_EVENT();
    
    if(ev == tcpip_event) {
      webclient_appcall(data);
    } else if(ev == ctk_signal_widget_activate) {
      if(w == (struct ctk_widget *)&backbutton) {
	firsty = 0;
	start_loading();
	
	--history_last;
	if(history_last > WWW_CONF_HISTORY_SIZE) {
	  history_last = WWW_CONF_HISTORY_SIZE - 1;
	}
	memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN);
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &backbutton);
      } else if(w == (struct ctk_widget *)&downbutton) {
	firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4;
	start_loading();
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
      } else if(w == (struct ctk_widget *)&gobutton ||
		w == (struct ctk_widget *)&urlentry) {
	start_loading();
	firsty = 0;
	
	log_back();
	memcpy(url, editurl, WWW_CONF_MAX_URLLEN);
	petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN);
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &gobutton);
      } else if(w == (struct ctk_widget *)&stopbutton) {
	loading = 0;
	webclient_close();
#if WWW_CONF_WITH_WGET
      } else if(w == (struct ctk_widget *)&wgetnobutton) {
	ctk_dialog_close();
      } else if(w == (struct ctk_widget *)&wgetyesbutton) {
	ctk_dialog_close();
	quit();
	argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN);
	if(argptr != NULL) {
	  strncpy(argptr, url, WWW_CONF_MAX_URLLEN);
	}
	program_handler_load("wget.prg", argptr);
#endif /* WWW_CONF_WITH_WGET */
#if WWW_CONF_FORMS
      } else {
	/* Check form buttons */
	for(i = 0; i < pagewidgetptr; ++i) {
	  if(&pagewidgets[i] == w) {
	    formsubmit(&pagewidgetattribs[i].form);
	    /*	  show_statustext(pagewidgetattribs[i].form.formaction);*/
	    /*	  PRINTF(("Formaction %s formname %s inputname %s\n",
		  pagewidgetattribs[i].form.formaction,
		  pagewidgetattribs[i].form.formname,
		  pagewidgetattribs[i].form.inputname));*/
	    break;
	  }
	}
#endif /* WWW_CONF_FORMS */
      }
    } else if(ev == ctk_signal_hyperlink_activate) {
      firsty = 0;
      log_back();
      open_link(w->widget.hyperlink.url);
      CTK_WIDGET_FOCUS(&mainwindow, &stopbutton);
      /*    ctk_window_open(&mainwindow);*/
    } else if(ev == ctk_signal_hyperlink_hover) {
      if(CTK_WIDGET_TYPE((struct ctk_widget *)data) ==
	 CTK_WIDGET_HYPERLINK) {
	strncpy(statustexturl, w->widget.hyperlink.url,
		sizeof(statustexturl));
	petsciiconv_topetscii(statustexturl, sizeof(statustexturl));
	show_statustext(statustexturl);
      }
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	open_url();
      } else {
	show_statustext("Host not found.");
      }
    } else if(ev == ctk_signal_window_close ||
	      ev == PROCESS_EVENT_EXIT) {
      quit();
    }
  }
  PROCESS_END();
}
Exemple #6
0
int main()
{
    initStrings();

    localizeStrings(PageLabels);

    localizeNewMenu(menu);

    if(!(OpenURLBase = IExec->OpenLibrary(OPENURLNAME, OPENURLVER)))
         return -1;
    if(!(IOpenURL = (struct OpenURLIFace*)IExec->GetInterface(OpenURLBase, "main", 1L, NULL)))
        return -1;

    RA_SetUpHook(idcmphook, IDCMPFunc, NULL);

    if((AppPort = IExec->AllocSysObjectTags(ASOT_PORT, TAG_DONE)) != NULL)
    {
        IExec->NewList(&list_Brow);
        IExec->NewList(&list_Mail);
        IExec->NewList(&list_FTPs);

        win = make_window();
        edit_brow_win = make_edit_brow_win();
        edit_mail_win = make_edit_mail_win();
        edit_ftp_win = make_edit_ftp_win();

        loadPrefs(URL_GetPrefs_Mode_InUse);

        // Set up inter-group label alignment

        iset(OBJ(OBJ_FTP_ALIGN1), LAYOUT_AlignLabels, OBJ(OBJ_FTP_ALIGN2));
        iset(OBJ(OBJ_MAIL_ALIGN1), LAYOUT_AlignLabels, OBJ(OBJ_MAIL_ALIGN2));
        iset(OBJ(OBJ_LBROWSER_BROW), ICA_TARGET, OBJ(OBJ_EDIT_BROW),
                                     ICA_MAP,    lst2btn);

        if((window = RA_OpenWindow(win)) != NULL)
        {
            uint32 sigmask;
            BOOL done = FALSE;

            sigmask = iget(win, WINDOW_SigMask);
            while (!done)
            {
                uint32 siggot;

                siggot = IExec->Wait(sigmask);
                if (siggot & sigmask)
                {
                    done = HandleInput_Main_Win();
                    HandleInput_Edit_Brow_Win();
                    HandleInput_Edit_Mail_Win();
                    HandleInput_Edit_FTP_Win();
                }
            }
        }
        IIntuition->DisposeObject(edit_ftp_win);
        IIntuition->DisposeObject(edit_mail_win);
        IIntuition->DisposeObject(edit_brow_win);
        IIntuition->DisposeObject(win);

        //  The hidden chooser isn't attached to anything,
        //  so we must dispose of it ourselves...

        IIntuition->DisposeObject(OBJ(OBJ_HIDDEN_CHOOSER));

        IListBrowser->FreeListBrowserList(&list_FTPs);
        IListBrowser->FreeListBrowserList(&list_Mail);
        IListBrowser->FreeListBrowserList(&list_Brow);
        IExec->FreeSysObject(ASOT_PORT, AppPort);
    }

    IExec->DropInterface((struct Interface*)IOpenURL);
    IExec->CloseLibrary(OpenURLBase);

    uninitStrings();

    return 0;
}
void test_cube_textured(GLint mag_filter, GLint min_filter,
		GLint wrap_s, GLint wrap_t, GLint wrap_r, GLenum format, GLenum type)
{
	GLint width, height;
	GLint modelviewmatrix_handle, modelviewprojectionmatrix_handle, normalmatrix_handle;
	GLuint texturename = 0, texture_handle;
	GLfloat vVertices[] = {
			// front
			-1.0f, -1.0f, +1.0f, // point blue
			+1.0f, -1.0f, +1.0f, // point magenta
			-1.0f, +1.0f, +1.0f, // point cyan
			+1.0f, +1.0f, +1.0f, // point white
			// back
			+1.0f, -1.0f, -1.0f, // point red
			-1.0f, -1.0f, -1.0f, // point black
			+1.0f, +1.0f, -1.0f, // point yellow
			-1.0f, +1.0f, -1.0f, // point green
			// right
			+1.0f, -1.0f, +1.0f, // point magenta
			+1.0f, -1.0f, -1.0f, // point red
			+1.0f, +1.0f, +1.0f, // point white
			+1.0f, +1.0f, -1.0f, // point yellow
			// left
			-1.0f, -1.0f, -1.0f, // point black
			-1.0f, -1.0f, +1.0f, // point blue
			-1.0f, +1.0f, -1.0f, // point green
			-1.0f, +1.0f, +1.0f, // point cyan
			// top
			-1.0f, +1.0f, +1.0f, // point cyan
			+1.0f, +1.0f, +1.0f, // point white
			-1.0f, +1.0f, -1.0f, // point green
			+1.0f, +1.0f, -1.0f, // point yellow
			// bottom
			-1.0f, -1.0f, -1.0f, // point black
			+1.0f, -1.0f, -1.0f, // point red
			-1.0f, -1.0f, +1.0f, // point blue
			+1.0f, -1.0f, +1.0f  // point magenta
	};

	GLfloat vTexCoords[] = {
			//front
			1.0f, 1.0f, //point blue
			0.0f, 1.0f, //point magenta
			1.0f, 0.0f, //point cyan
			0.0f, 0.0f, //point white
			//back
			1.0f, 1.0f, //point red
			0.0f, 1.0f, //point black
			1.0f, 0.0f, //point yellow
			0.0f, 0.0f, //point green
			//right
			1.0f, 1.0f, //point magenta
			0.0f, 1.0f, //point red
			1.0f, 0.0f, //point white
			0.0f, 0.0f, //point yellow
			//left
			1.0f, 1.0f, //point black
			0.0f, 1.0f, //point blue
			1.0f, 0.0f, //point green
			0.0f, 0.0f, //point cyan
			//top
			1.0f, 1.0f, //point cyan
			0.0f, 1.0f, //point white
			1.0f, 0.0f, //point green
			0.0f, 0.0f, //point yellow
			//bottom
			1.0f, 0.0f, //point black
			0.0f, 0.0f, //point red
			1.0f, 1.0f, //point blue
			0.0f, 1.0f, //point magenta
	};

	GLfloat vNormals[] = {
			// front
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			+0.0f, +0.0f, +1.0f, // forward
			// back
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			+0.0f, +0.0f, -1.0f, // backbard
			// right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			+1.0f, +0.0f, +0.0f, // right
			// left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			-1.0f, +0.0f, +0.0f, // left
			// top
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			+0.0f, +1.0f, +0.0f, // up
			// bottom
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f, // down
			+0.0f, -1.0f, +0.0f  // down
	};
	EGLSurface surface;
	const int texwidth = 333;
	const int texheight = 222;
	static uint8_t *buf = NULL;

	if (!buf) {
		int i;
		buf = malloc(texwidth * texheight * 16);
		for (i = 0; i < (texwidth * texheight * 16); i++)
			buf[i] = i;
	}

	RD_START("cube-textured", "mag_filter=%04x, min_filter=%04x, "
			"wrap_s=%04x, wrap_t=%04x, wrap_r=%04x, format=%s, type=%s",
			mag_filter, min_filter, wrap_s, wrap_t, wrap_r,
			formatname(format), typename(type));

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 256, 256);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "in_position"));
	GCHK(glBindAttribLocation(program, 1, "in_normal"));
	GCHK(glBindAttribLocation(program, 2, "in_TexCoord"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));


	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, vNormals));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(2));

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
	esRotate(&modelview, 45.0f, 1.0f, 0.0f, 0.0f);
	esRotate(&modelview, 45.0f, 0.0f, 1.0f, 0.0f);
	esRotate(&modelview, 10.0f, 0.0f, 0.0f, 1.0f);

	GLfloat aspect = (GLfloat)(height) / (GLfloat)(width);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection, -2.8f, +2.8f, -2.8f * aspect, +2.8f * aspect, 6.0f, 10.0f);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glGenTextures(1, &texturename));
	GCHK(glBindTexture(GL_TEXTURE_2D, texturename));
	GCHK(glTexImage2D(GL_TEXTURE_2D, 0, format, texwidth, texheight,
			0, format, type, buf));

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R_OES, wrap_r));

	GCHK(modelviewmatrix_handle = glGetUniformLocation(program, "modelviewMatrix"));
	GCHK(modelviewprojectionmatrix_handle = glGetUniformLocation(program, "modelviewprojectionMatrix"));
	GCHK(normalmatrix_handle = glGetUniformLocation(program, "normalMatrix"));
	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));

	GCHK(glUniformMatrix4fv(modelviewmatrix_handle, 1, GL_FALSE, &modelview.m[0][0]));
	GCHK(glUniformMatrix4fv(modelviewprojectionmatrix_handle, 1, GL_FALSE, &modelviewprojection.m[0][0]));
	GCHK(glUniformMatrix3fv(normalmatrix_handle, 1, GL_FALSE, normal));
	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glEnable(GL_CULL_FACE));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 4, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 8, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 12, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 16, 4));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 20, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Exemple #8
0
/* Run through multiple variants to detect clear color, quad color (frag
 * shader param), and vertices
 */
void test_query(int querytype, int w, int h)
{
	static const GLfloat clear_color[] = {0.0, 0.0, 0.0, 0.0};
	static const GLfloat quad_color[]  = {1.0, 0.0, 0.0, 1.0};
	static const GLfloat quad2_color[]  = {0.0, 1.0, 0.0, 1.0};
	static const GLfloat vertices[] = {
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0,
	};
	static const GLfloat vertices2[] = {
			-0.15, -0.23, 1.0,
			 0.25, -0.33, 1.0,
			-0.35,  0.43, 1.0,
			 0.45,  0.53, 1.0,
	};
	static const char *queryname[] = {
			"none",
			"samples-passed",
			"time-elapsed",
	};

	RD_START("query", "query=%s", queryname[querytype]);
	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, w, h);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));

	link_program(program);

	GCHK(glGenQueries(1, &query));

	GCHK(glDepthMask(GL_TRUE));
	GCHK(glEnable(GL_DEPTH_TEST));

	GCHK(glViewport(0, 0, width, height));

	if (clear_color) {
		/* clear the color buffer */
		GCHK(glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]));
		GCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
	}

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices));
	GCHK(glEnableVertexAttribArray(0));

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glUniform4fv(uniform_location, 1, quad_color));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	switch (querytype) {
	case 1:
		GCHK(glBeginQuery(GL_ANY_SAMPLES_PASSED, query));
		break;
	case 2:
		GCHK(glBeginQuery(GL_TIME_ELAPSED_EXT, query));
		break;
	}

	/* Quad 2 render */
	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices2));

	/* now set up our uniform. */
	GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

	GCHK(glUniform4fv(uniform_location, 1, quad2_color));
	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	switch (querytype) {
	case 1:
		GCHK(glEndQuery(GL_ANY_SAMPLES_PASSED));
		break;
	case 2:
		GCHK(glEndQuery(GL_TIME_ELAPSED_EXT));
		break;
	}

	if (querytype > 0) {
		GLuint result;
		do
		{
			GCHK(glGetQueryObjectuiv(query, GL_QUERY_RESULT_AVAILABLE, &result));
		} while (!result);
		GCHK(glGetQueryObjectuiv(query, GL_QUERY_RESULT, &result));

		DEBUG_MSG("Query ended with %d", result);

	}

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	usleep(1000000);

	GCHK(glDeleteQueries(1, &query));

	eglTerminate(display);

	RD_END();
}
Exemple #9
0
void test_quad_instanced(int instances, int div0, int div1)
{
	GLint width, height;
	GLuint texturename = 0, texture_handle;
	GLfloat vVertices[] = {
			// front
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0
	};

	GLfloat vTexCoords[] = {
			1.0f, 1.0f,
			0.0f, 1.0f,
			1.0f, 0.0f,
			0.0f, 0.0f,
	};

	EGLSurface surface;

	RD_START("instanced", "instances=%d, div0=%d, div1=%d", instances, div0, div1);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 255, 255);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	printf("EGL Version %s\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor %s\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions %s\n", eglQueryString(display, EGL_EXTENSIONS));
	printf("GL Version %s\n", glGetString(GL_VERSION));
	printf("GL extensions: %s\n", glGetString(GL_EXTENSIONS));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "in_position"));
	GCHK(glBindAttribLocation(program, 1, "in_TexCoord"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glGenTextures(1, &texturename));
	GCHK(glBindTexture(GL_TEXTURE_2D, texturename));

	GCHK(glTexImage2D(
			GL_TEXTURE_2D, 0, GL_RGB,
			cube_texture.width, cube_texture.height, 0,
			GL_RGB, GL_UNSIGNED_BYTE, cube_texture.pixel_data));

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));


	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));

	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glEnable(GL_CULL_FACE));

	if (instances > 0) {
		GCHK(glVertexAttribDivisor(0, div0));
		GCHK(glVertexAttribDivisor(1, div1));
		GCHK(glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, instances));
	} else {
		GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
	}

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	sleep(1);

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Exemple #10
0
void test_stencil(void)
{
    GLint numStencilBits;
    GLuint stencilValues[NumTests] = {
        0x7, // Result of test 0
        0x0, // Result of test 1
        0x2, // Result of test 2
        0xff // Result of test 3.  We need to fill this value in a run-time
    };
    int i;

    RD_START("stencil", "");

    display = get_display();

    /* get an appropriate EGL frame buffer configuration */
    ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
    DEBUG_MSG("num_config: %d", num_config);

    /* create an EGL rendering context */
    ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

    surface = make_window(display, config, 400, 240);

    ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
    ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

    DEBUG_MSG("Buffer: %dx%d", width, height);

    /* connect the context to the surface */
    ECHK(eglMakeCurrent(display, surface, surface, context));

    program = get_program(vertex_shader_source, fragment_shader_source);

    GCHK(glBindAttribLocation(program, 0, "aPosition"));

    link_program(program);

    /* now set up our uniform. */
    GCHK(uniform_location = glGetUniformLocation(program, "uColor"));

    GCHK(glClearColor(0.0, 0.0, 0.0, 0.0));
    GCHK(glClearStencil(0x1));
    GCHK(glClearDepthf(0.75));

    GCHK(glEnable(GL_DEPTH_TEST));
    GCHK(glEnable(GL_STENCIL_TEST));

    // Set the viewport
    GCHK(glViewport(0, 0, width, height));

    // Clear the color, depth, and stencil buffers.  At this
    //   point, the stencil buffer will be 0x1 for all pixels
    GCHK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));

    // Use the program object
    GCHK(glUseProgram(program));

    // Load the vertex position
    GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));

    GCHK(glEnableVertexAttribArray(0));

    // Test 0:
    //
    // Initialize upper-left region.  In this case, the
    //   stencil-buffer values will be replaced because the
    //   stencil test for the rendered pixels will fail the
    //   stencil test, which is
    //
    //        ref   mask   stencil  mask
    //      ( 0x7 & 0x3 ) < ( 0x1 & 0x7 )
    //
    //   The value in the stencil buffer for these pixels will
    //   be 0x7.
    //
    GCHK(glStencilFunc(GL_LESS, 0x7, 0x3));
    GCHK(glStencilOp(GL_REPLACE, GL_DECR, GL_DECR));
    GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[0]));

    // Test 1:
    //
    // Initialize the upper-right region.  Here, we'll decrement
    //   the stencil-buffer values where the stencil test passes
    //   but the depth test fails.  The stencil test is
    //
    //        ref  mask    stencil  mask
    //      ( 0x3 & 0x3 ) > ( 0x1 & 0x3 )
    //
    //    but where the geometry fails the depth test.  The
    //    stencil values for these pixels will be 0x0.
    //
    GCHK(glStencilFunc(GL_GREATER, 0x3, 0x3));
    GCHK(glStencilOp(GL_KEEP, GL_DECR, GL_KEEP));
    GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[1]));

    // Test 2:
    //
    // Initialize the lower-left region.  Here we'll increment
    //   (with saturation) the stencil value where both the
    //   stencil and depth tests pass.  The stencil test for
    //   these pixels will be
    //
    //        ref  mask     stencil  mask
    //      ( 0x1 & 0x3 ) == ( 0x1 & 0x3 )
    //
    //   The stencil values for these pixels will be 0x2.
    //
    GCHK(glStencilFunc(GL_EQUAL, 0x1, 0x3));
    GCHK(glStencilOp(GL_KEEP, GL_INCR, GL_INCR));
    GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[2]));

    // Test 3:
    //
    // Finally, initialize the lower-right region.  We'll invert
    //   the stencil value where the stencil tests fails.  The
    //   stencil test for these pixels will be
    //
    //        ref   mask    stencil  mask
    //      ( 0x2 & 0x1 ) == ( 0x1 & 0x1 )
    //
    //   The stencil value here will be set to ~((2^s-1) & 0x1),
    //   (with the 0x1 being from the stencil clear value),
    //   where 's' is the number of bits in the stencil buffer
    //
    GCHK(glStencilFunc(GL_EQUAL, 0x2, 0x1));
    GCHK(glStencilOp(GL_INVERT, GL_KEEP, GL_KEEP));
    GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[3]));

    // Since we don't know at compile time how many stencil bits are present,
    //   we'll query, and update the value correct value in the
    //   stencilValues arrays for the fourth tests.  We'll use this value
    //   later in rendering.
    GCHK(glGetIntegerv(GL_STENCIL_BITS, &numStencilBits));

    stencilValues[3] = ~(((1 << numStencilBits) - 1) & 0x1) & 0xff;

    // Use the stencil buffer for controlling where rendering will
    //   occur.  We disable writing to the stencil buffer so we
    //   can test against them without modifying the values we
    //   generated.
    GCHK(glStencilMask(0x0));

    for (i = 0; i < NumTests; i++) {
        GCHK(glStencilFunc(GL_EQUAL, stencilValues[i], 0xff));
        GCHK(glUniform4fv(uniform_location, 1, colors[i]));
        GCHK(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices[4]));
    }

    ECHK(eglSwapBuffers(display, surface));
    GCHK(glFlush());

    ECHK(eglDestroySurface(display, surface));

    usleep(1000000);

    dump_bmp(display, surface, "stencil.bmp");

    ECHK(eglTerminate(display));

    RD_END();
}
Exemple #11
0
void test_cat(void)
{
	GLint width, height;
	GLint modelviewmatrix_handle, modelviewprojectionmatrix_handle, normalmatrix_handle;
	GLuint position_vbo, normal_vbo;
	EGLSurface surface;
	float scale = 1.3;

	RD_START("cat", "");

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 400, 240);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "normal"));
	GCHK(glBindAttribLocation(program, 1, "position"));

	/* upload the attribute vbo's, only done once: */
	GCHK(glGenBuffers(1, &normal_vbo));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, normal_vbo));
	GCHK(glBufferData(GL_ARRAY_BUFFER, sizeof(cat_normal), cat_normal, GL_STATIC_DRAW));

	GCHK(glGenBuffers(1, &position_vbo));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, position_vbo));
	GCHK(glBufferData(GL_ARRAY_BUFFER, sizeof(cat_position), cat_position, GL_STATIC_DRAW));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glEnable(GL_DEPTH_TEST));
	GCHK(glDepthFunc(GL_LEQUAL));
	GCHK(glEnable(GL_CULL_FACE));
	GCHK(glCullFace(GL_BACK));
	GCHK(glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT));

	GCHK(glEnableVertexAttribArray(0));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, normal_vbo));
	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL));

	GCHK(glEnableVertexAttribArray(1));
	GCHK(glBindBuffer(GL_ARRAY_BUFFER, position_vbo));
	GCHK(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL));

	ESMatrix modelview;
	esMatrixLoadIdentity(&modelview);
	esTranslate(&modelview, 0.0f, 0.0f, -8.0f);
	esRotate(&modelview, 45.0f, 0.0f, 1.0f, 0.0f);

	GLfloat aspect = (GLfloat)(height) / (GLfloat)(width);

	ESMatrix projection;
	esMatrixLoadIdentity(&projection);
	esFrustum(&projection,
			-scale, +scale,
			-scale * aspect, +scale * aspect,
			5.5f, 10.0f);

	ESMatrix modelviewprojection;
	esMatrixLoadIdentity(&modelviewprojection);
	esMatrixMultiply(&modelviewprojection, &modelview, &projection);

	float normal[9];
	normal[0] = modelview.m[0][0];
	normal[1] = modelview.m[0][1];
	normal[2] = modelview.m[0][2];
	normal[3] = modelview.m[1][0];
	normal[4] = modelview.m[1][1];
	normal[5] = modelview.m[1][2];
	normal[6] = modelview.m[2][0];
	normal[7] = modelview.m[2][1];
	normal[8] = modelview.m[2][2];

	GCHK(modelviewmatrix_handle = glGetUniformLocation(program, "ModelViewMatrix"));
	GCHK(modelviewprojectionmatrix_handle = glGetUniformLocation(program, "ModelViewProjectionMatrix"));
	GCHK(normalmatrix_handle = glGetUniformLocation(program, "NormalMatrix"));

	GCHK(glUniformMatrix4fv(modelviewmatrix_handle, 1, GL_FALSE, &modelview.m[0][0]));
	GCHK(glUniformMatrix4fv(modelviewprojectionmatrix_handle, 1, GL_FALSE, &modelviewprojection.m[0][0]));
	GCHK(glUniformMatrix3fv(normalmatrix_handle, 1, GL_FALSE, normal));

	GCHK(glDrawArrays(GL_TRIANGLES, 0, cat_vertices));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
IntersectionInterface::IntersectionInterface() {
  m_intersectionWindow = make_window();
  intersectionUI.setUI( this );
  intersectionUI.changeShape( ShapesUI::SHAPE_SPHERE );
}
void test_strip_smoothed(int fbo)
{
	GLint width, height;
	GLfloat vVertices[] = {
			-0.7,  0.7, -0.7,
			-0.7,  0.2, -0.4,
			 0.0,  0.3, -0.5,
			-0.2, -0.3,  0.3,
			 0.5, -0.2,  0.4,
			 0.7, -0.7,  0.7 };
	GLfloat vColors[] = {
			0.1, 0.1, 0.1, 1.0,
			1.0, 0.0, 0.0, 1.0,
			0.0, 0.0, 1.0, 1.0,
			1.0, 1.0, 0.0, 1.0,
			0.0, 1.0, 1.0, 1.0,
			0.9, 0.9, 0.9, 1.0};
	EGLSurface surface;

	RD_START("strip-smoothed", "fbo=%d", fbo);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 256, 256);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));
	GCHK(glBindAttribLocation(program, 1, "aColor"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	if (fbo)
		GCHK(setup_fbo(width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.3125, 0.3125, 0.3125, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, vColors));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 6));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	if (fbo)
		GCHK(cleanup_fbo());

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Exemple #14
0
/* www_process():
 *
 * The program's signal dispatcher function. Is called whenever a signal arrives.
 */
PROCESS_THREAD(www_process, ev, data)
{
  static struct ctk_widget *w;
  static unsigned char i;
#if WWW_CONF_WITH_WGET
  static char *argptr;
#endif /* WWW_CONF_WITH_WGET */

  w = (struct ctk_widget *)data;

  PROCESS_BEGIN();

  /* Create the main window. */
  memset(webpage, 0, sizeof(webpage));
  ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH,
		 WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser");
  make_window();
#ifdef WWW_CONF_HOMEPAGE
  strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl));
#endif /* WWW_CONF_HOMEPAGE */
  CTK_WIDGET_FOCUS(&mainwindow, &urlentry);

#if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC)
#if CTK_CONF_WINDOWS
  /* Create download dialog.*/
  ctk_dialog_new(&wgetdialog, 38, 7);
  CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1);
  CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2);
  CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton);
  CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton);
#endif /* CTK_CONF_WINDOWS */
#endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */

  ctk_window_open(&mainwindow);

  while(1) {

    PROCESS_WAIT_EVENT();

    if(ev == tcpip_event) {
      webclient_appcall(data);
    } else if(ev == ctk_signal_widget_activate) {
      if(w == (struct ctk_widget *)&gobutton ||
	 w == (struct ctk_widget *)&urlentry) {
	start_loading();
	firsty = 0;
#if WWW_CONF_HISTORY_SIZE > 0
	log_back();
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
	memcpy(url, editurl, WWW_CONF_MAX_URLLEN);
	petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN);
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &gobutton);
#if WWW_CONF_HISTORY_SIZE > 0
      } else if(w == (struct ctk_widget *)&backbutton) {
	firsty = 0;
	start_loading();
	--history_last;
	if(history_last > WWW_CONF_HISTORY_SIZE) {
	  history_last = WWW_CONF_HISTORY_SIZE - 1;
	}
	memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN);
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &backbutton);
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
      } else if(w == (struct ctk_widget *)&downbutton) {
	firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4;
	start_loading();
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
      } else if(w == (struct ctk_widget *)&stopbutton) {
	loading = 0;
	webclient_close();
#if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC)
      } else if(w == (struct ctk_widget *)&wgetnobutton) {
#if CTK_CONF_WINDOWS
	ctk_dialog_close();
#else /* CTK_CONF_WINDOWS */
	clear_page();
#endif /* CTK_CONF_WINDOWS */
      } else if(w == (struct ctk_widget *)&wgetyesbutton) {
#if CTK_CONF_WINDOWS
	ctk_dialog_close();
#else /* CTK_CONF_WINDOWS */
	clear_page();
#endif /* CTK_CONF_WINDOWS */
#if WWW_CONF_WITH_WGET
	quit();
	argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN);
	if(argptr != NULL) {
	  strncpy(argptr, url, WWW_CONF_MAX_URLLEN);
	}
	program_handler_load("wget.prg", argptr);
#else /* WWW_CONF_WITH_WGET */
	petsciiconv_topetscii(url, sizeof(url));
	/* Clear screen */
	ctk_restore();
	WWW_CONF_WGET_EXEC(url);
	redraw_window();
	show_statustext("Cannot exec wget");
#endif /* WWW_CONF_WITH_WGET */
#endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */
#if WWW_CONF_FORMS
      } else {
	/* Assume form widget. */
	struct inputattrib *input = (struct inputattrib *)
				      (((char *)w) - offsetof(struct inputattrib, widget));
	formsubmit(input->formptr);
#endif /* WWW_CONF_FORMS */
      }
    } else if(ev == ctk_signal_hyperlink_activate) {
      firsty = 0;
#if WWW_CONF_HISTORY_SIZE > 0
      log_back();
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
      set_link(w->widget.hyperlink.url);
      show_url();
      open_url();
      start_loading();
      CTK_WIDGET_FOCUS(&mainwindow, &stopbutton);
    } else if(ev == ctk_signal_hyperlink_hover) {
      if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) {
	strncpy(statustexturl, w->widget.hyperlink.url,
		sizeof(statustexturl));
	petsciiconv_topetscii(statustexturl, sizeof(statustexturl));
	show_statustext(statustexturl);
      }
#if UIP_UDP
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
	open_url();
      } else {
	show_statustext("Host not found");
      }
#endif /* UIP_UDP */
    } else if(ev == ctk_signal_window_close ||
	      ev == PROCESS_EVENT_EXIT) {
      quit();
    }
  }
Exemple #15
0
void test_quad_textured(int shadow, int cfunc)
{
	GLint width, height;
	GLuint textures[2], texture_handle;
	GLfloat vVertices[] = {
			// front
			-0.45, -0.75, 0.0,
			 0.45, -0.75, 0.0,
			-0.45,  0.75, 0.0,
			 0.45,  0.75, 0.0
	};

	GLfloat vTexCoords[] = {
			1.0f, 1.0f,
			0.0f, 1.0f,
			1.0f, 0.0f,
			0.0f, 0.0f,
	};

	EGLSurface surface;

	RD_START("quad-textured", "shadow=%d, cfunc=%x", shadow, cfunc);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 255, 255);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	printf("EGL Version %s\n", eglQueryString(display, EGL_VERSION));
	printf("EGL Vendor %s\n", eglQueryString(display, EGL_VENDOR));
	printf("EGL Extensions %s\n", eglQueryString(display, EGL_EXTENSIONS));
	printf("GL Version %s\n", glGetString(GL_VERSION));
	printf("GL extensions: %s\n", glGetString(GL_EXTENSIONS));

	program = get_program(vertex_shader_source, shadow ?
			fragment_shader_source_shadow : fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "in_position"));
	GCHK(glBindAttribLocation(program, 1, "in_TexCoord"));

	link_program(program);

	GCHK(glViewport(0, 0, width, height));

	/* clear the color buffer */
	GCHK(glClearColor(0.5, 0.5, 0.5, 1.0));
	GCHK(glClear(GL_COLOR_BUFFER_BIT));

	GCHK(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices));
	GCHK(glEnableVertexAttribArray(0));

	GCHK(glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, vTexCoords));
	GCHK(glEnableVertexAttribArray(1));

	GCHK(glGenTextures(2, &textures));

	GCHK(glActiveTexture(GL_TEXTURE0));
	GCHK(glBindTexture(GL_TEXTURE_2D, textures[0]));

	if (shadow) {
		GCHK(glTexImage2D(
				GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
				cube_texture.width/2, cube_texture.height/2, 0,
				GL_DEPTH_COMPONENT, GL_FLOAT, cube_texture.pixel_data));
	} else {
		GCHK(glTexImage2D(
				GL_TEXTURE_2D, 0, GL_RGB,
				cube_texture.width, cube_texture.height, 0,
				GL_RGB, GL_UNSIGNED_BYTE, cube_texture.pixel_data));
	}

	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));

	if (shadow) {
#define GL_TEXTURE_COMPARE_MODE           0x884C
#define GL_TEXTURE_COMPARE_FUNC           0x884D
#define GL_COMPARE_REF_TO_TEXTURE         0x884E
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
				GL_COMPARE_REF_TO_TEXTURE));
		GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC,
				cfunc));
	} else {
		float minlod = cfunc, maxlod = cfunc;
		GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, minlod));
		GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, maxlod));
		switch (cfunc) {
		case 0:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
			break;
		case 1:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST));
			break;
		case 2:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST));
			break;
		case 3:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR));
			break;
		case 4:
			GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
			break;
#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT
#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE
#endif
		case 5:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4));
			break;
		case 6:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8));
			break;
		case 7:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16));
			break;
		case 8:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 32));
			break;
		case 9:
			GCHK(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 320));
			break;
		}
	}

	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));
	GCHK(glUniform1i(texture_handle, 0)); /* '0' refers to texture unit 0. */

	GCHK(glActiveTexture(GL_TEXTURE1));
	GCHK(glBindTexture(GL_TEXTURE_2D, textures[1]));

	GCHK(glTexImage2D(
			GL_TEXTURE_2D, 0, GL_RGBA,
			cube_texture.width/3, cube_texture.height-1, 0,
			GL_RGBA, GL_UNSIGNED_BYTE, cube_texture.pixel_data+1));

	/* Note: cube turned black until these were defined. */
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE));

	GCHK(texture_handle = glGetUniformLocation(program, "uTexture"));
	GCHK(glUniform1i(texture_handle, 1)); /* '1' refers to texture unit 1. */

	GCHK(glEnable(GL_CULL_FACE));

	GCHK(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));

	ECHK(eglSwapBuffers(display, surface));
	GCHK(glFlush());

	sleep(1);

	ECHK(eglDestroySurface(display, surface));

	ECHK(eglTerminate(display));

	RD_END();
}
Exemple #16
0
/* Run through multiple variants to detect mrt settings
 */
void test_srgb_fbo(GLint ifmt, GLenum fmt, GLenum type)
{
	GLint width, height;
	GLuint fbo, fbotex;
	GLenum mrt_bufs[16];

	GLfloat quad_color[] =  {1.0, 0.0, 0.0, 1.0};
	GLfloat vertices[] = {
			-0.45, -0.75, 0.1,
			 0.45, -0.75, 0.1,
			-0.45,  0.75, 0.1,
			 0.45,  0.75, 0.1 };
	EGLSurface surface;

	RD_START("srgb-fbo", "fmt=%s (%x), ifmt=%s (%x), type=%s (%x)",
			formatname(fmt), fmt,
			formatname(ifmt), ifmt,
			typename(type), type);

	display = get_display();

	/* get an appropriate EGL frame buffer configuration */
	ECHK(eglChooseConfig(display, config_attribute_list, &config, 1, &num_config));
	DEBUG_MSG("num_config: %d", num_config);

	/* create an EGL rendering context */
	ECHK(context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribute_list));

	surface = make_window(display, config, 64, 64);

	ECHK(eglQuerySurface(display, surface, EGL_WIDTH, &width));
	ECHK(eglQuerySurface(display, surface, EGL_HEIGHT, &height));

	DEBUG_MSG("Buffer: %dx%d", width, height);

	/* connect the context to the surface */
	ECHK(eglMakeCurrent(display, surface, surface, context));

	program = get_program(vertex_shader_source, fragment_shader_source);

	GCHK(glBindAttribLocation(program, 0, "aPosition"));

	link_program(program);

	GCHK(glGenFramebuffers(1, &fbo));
	GCHK(glGenTextures(1, &fbotex));
	GCHK(glBindFramebuffer(GL_FRAMEBUFFER, fbo));

	GCHK(glBindTexture(GL_TEXTURE_2D, fbotex));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
	GCHK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
	GCHK(glTexImage2D(GL_TEXTURE_2D, 0, ifmt, width, height, 0, fmt, type, 0));
	GCHK(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			GL_TEXTURE_2D, fbotex, 0));

	DEBUG_MSG("status=%04x", glCheckFramebufferStatus(GL_FRAMEBUFFER));

	GCHK(glBindFramebuffer(GL_FRAMEBUFFER, fbo));

	GCHK(glDrawBuffers(1, (const GLenum[]){GL_COLOR_ATTACHMENT0}));