Skip to content

Instantly share code, notes, and snippets.

@kaneta1992
Created June 28, 2015 16:49
Show Gist options
  • Save kaneta1992/1a4067a7419f97d8cefc to your computer and use it in GitHub Desktop.
Save kaneta1992/1a4067a7419f97d8cefc to your computer and use it in GitHub Desktop.
emscriptenOpenGLES2.0初期化サンプル
#include <stdio.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <emscripten.h>
int main()
{
//キャンバスサイズ指定
emscripten_set_canvas_size(256,256);
//ディスプレイ取得
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
//GL初期化
eglInitialize(display, NULL, NULL);
//フレームバッファ構成を取得
EGLint bufferAttribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_NONE
};
EGLConfig config;
eglChooseConfig(display, bufferAttribs, &config, 1, NULL);
//サーフェース作成
EGLNativeWindowType dummy;
EGLSurface surface = eglCreateWindowSurface(display, config, dummy, NULL);
//APIバインド
eglBindAPI(EGL_OPENGL_ES_API);
// レンダリングコンテキスト作成
EGLint contextAttribs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLContext context = eglCreateContext(display, config, NULL, contextAttribs);
//ディスプレイ、サーフェース、コンテキストリンク
eglMakeCurrent(display, surface, surface, context);
//画面クリア
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
//コンソールにWebGLの情報出力
printf("%s\n", glGetString(GL_VENDOR));
printf("%s\n", glGetString(GL_RENDERER));
printf("%s\n", glGetString(GL_VERSION));
//コンソールにフレームバッファ構成出力
EGLint val;
eglGetConfigAttrib(display, config, EGL_RED_SIZE, &val);
printf("EGL_RED_SIZE:%d\n", (int)val);
eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &val);
printf("EGL_GREEN_SIZE:%d\n", (int)val);
eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &val);
printf("EGL_BLUE_SIZE:%d\n", (int)val);
eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &val);
printf("EGL_ALPHA_SIZE:%d\n", (int)val);
eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &val);
printf("EGL_DEPTH_SIZE:%d\n", (int)val);
//リソース解放
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(display, surface);
eglDestroyContext(display, context);
eglTerminate(display);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment