132001f49Smrg/*
232001f49Smrg * Mesa 3-D graphics library
332001f49Smrg * Version:  7.9
432001f49Smrg *
532001f49Smrg * Copyright (C) 2010 LunarG Inc.
632001f49Smrg *
732001f49Smrg * Permission is hereby granted, free of charge, to any person obtaining a
832001f49Smrg * copy of this software and associated documentation files (the "Software"),
932001f49Smrg * to deal in the Software without restriction, including without limitation
1032001f49Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1132001f49Smrg * and/or sell copies of the Software, and to permit persons to whom the
1232001f49Smrg * Software is furnished to do so, subject to the following conditions:
1332001f49Smrg *
1432001f49Smrg * The above copyright notice and this permission notice shall be included
1532001f49Smrg * in all copies or substantial portions of the Software.
1632001f49Smrg *
1732001f49Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1832001f49Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1932001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2032001f49Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2132001f49Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2232001f49Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2332001f49Smrg * DEALINGS IN THE SOFTWARE.
2432001f49Smrg *
2532001f49Smrg * Authors:
2632001f49Smrg *    Chia-I Wu <olv@lunarg.com>
2732001f49Smrg */
2832001f49Smrg
2932001f49Smrg/*
3032001f49Smrg * This demo tests eglGetProcAddress and glClear.
3132001f49Smrg */
3232001f49Smrg
3332001f49Smrg#include <stdlib.h>
3432001f49Smrg#include <stdio.h>
3532001f49Smrg#include <EGL/egl.h>
3632001f49Smrg#include <GLES/gl.h>
3732001f49Smrg
3832001f49Smrg#include "eglut.h"
3932001f49Smrg
4032001f49Smrgtypedef void (GL_APIENTRY *type_ClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
4132001f49Smrgtypedef void (GL_APIENTRY *type_Clear)(GLbitfield mask);
4232001f49Smrg
4332001f49Smrgstatic type_ClearColor fn_ClearColor;
4432001f49Smrgstatic type_Clear fn_Clear;
4532001f49Smrg
4632001f49Smrgstatic void
4732001f49Smrgdraw(void)
4832001f49Smrg{
4932001f49Smrg   fn_Clear(GL_COLOR_BUFFER_BIT);
5032001f49Smrg}
5132001f49Smrg
5232001f49Smrgstatic void *
5332001f49Smrgget_proc(const char *name)
5432001f49Smrg{
5532001f49Smrg   void *proc;
5632001f49Smrg
5732001f49Smrg   proc = (void *) eglGetProcAddress(name);
5832001f49Smrg   if (!proc) {
5932001f49Smrg      /*
6032001f49Smrg       * note that eglGetProcAddress is not required to support non-extension
6132001f49Smrg       * functions
6232001f49Smrg       */
6332001f49Smrg      printf("failed to find %s (not necessarily a bug)\n", name);
6432001f49Smrg      exit(1);
6532001f49Smrg   }
6632001f49Smrg
6732001f49Smrg   return proc;
6832001f49Smrg}
6932001f49Smrg
7032001f49Smrgstatic void
7132001f49Smrginit(void)
7232001f49Smrg{
7332001f49Smrg   fn_ClearColor = (type_ClearColor) get_proc("glClearColor");
7432001f49Smrg   fn_Clear = (type_Clear) get_proc("glClear");
7532001f49Smrg
7632001f49Smrg   fn_ClearColor(1.0, 0.4, 0.4, 0.0);
7732001f49Smrg}
7832001f49Smrg
7932001f49Smrgint
8032001f49Smrgmain(int argc, char *argv[])
8132001f49Smrg{
8232001f49Smrg   eglutInitWindowSize(300, 300);
8332001f49Smrg   eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
8432001f49Smrg   eglutInit(argc, argv);
8532001f49Smrg
8632001f49Smrg   eglutCreateWindow("clear");
8732001f49Smrg
8832001f49Smrg   eglutDisplayFunc(draw);
8932001f49Smrg
9032001f49Smrg   init();
9132001f49Smrg
9232001f49Smrg   eglutMainLoop();
9332001f49Smrg
9432001f49Smrg   return 0;
9532001f49Smrg}
96