/*
* This proprietary software may be used only as
* authorised by a licensing agreement from ARM Limited
* (C) COPYRIGHT 2009 - 2010 ARM Limited
* ALL RIGHTS RESERVED
* The entire notice above must be reproduced on all authorised
* copies and copies may only be made to the extent permitted
* by a licensing agreement from ARM Limited.
*/
#include "cube.h"
#include "shader.h"
#include "window.h"
#include "matrix.h"
#include "GLES2/gl2.h"
#include "EGL/egl.h"
#ifdef _WIN32
HWND hWindow;
HDC hDisplay;
#else
Window hWindow;
Display *hDisplay;
#endif
/* 3D data. Vertex range -0.5..0.5 in all axes.
* Z -0.5 is near, 0.5 is far. */
const float aVertices[] =
{
/* Front face. */
/* Bottom left */
-0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
-0.5, -0.5, -0.5,
/* Top right */
-0.5, 0.5, -0.5,
0.5, 0.5, -0.5,
0.5, -0.5, -0.5,
/* Left face */
/* Bottom left */
-0.5, 0.5, 0.5,
-0.5, -0.5, -0.5,
-0.5, -0.5, 0.5,
/* Top right */
-0.5, 0.5, 0.5,
-0.5, 0.5, -0.5,
-0.5, -0.5, -0.5,
/* Top face */
/* Bottom left */
-0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
-0.5, 0.5, -0.5,
/* Top right */
-0.5, 0.5, 0.5,
0.5, 0.5, 0.5,
0.5, 0.5, -0.5,
/* Right face */
/* Bottom left */
0.5, 0.5, -0.5,
0.5, -0.5, 0.5,
0.5, -0.5, -0.5,
/* Top right */
0.5, 0.5, -0.5,
0.5, 0.5, 0.5,
0.5, -0.5, 0.5,
/* Back face */
/* Bottom left */
0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
0.5, -0.5, 0.5,
/* Top right */
0.5, 0.5, 0.5,
-0.5, 0.5, 0.5,
-0.5, -0.5, 0.5,
/* Bottom face */
/* Bottom left */
-0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
-0.5, -0.5, 0.5,
/* Top right */
-0.5, -0.5, -0.5,
0.5, -0.5, -0.5,
0.5, -0.5, 0.5,
};
const float aColours[] =
{
/* Front face */
/* Bottom left */
1.0, 0.0, 0.0, /* red */
0.0, 0.0, 1.0, /* blue */
0.0, 1.0, 0.0, /* green */
/* Top right */
1.0, 0.0, 0.0, /* red */
1.0, 1.0, 0.0, /* yellow */
0.0, 0.0, 1.0, /* blue */
/* Left face */
/* Bottom left */
1.0, 1.0, 1.0, /* white */
0.0, 1.0, 0.0, /* green */
0.0, 1.0, 1.0, /* cyan */
/* Top right */
1.0, 1.0, 1.0, /* white */
1.0, 0.0, 0.0, /* red */
0.0, 1.0, 0.0, /* green */
/* Top face */
/* Bottom left */
1.0, 1.0, 1.0, /* white */
1.0, 1.0, 0.0, /* yellow */
1.0, 0.0, 0.0, /* red */
/* Top right */
1.0, 1.0, 1.0, /* white */
0.0, 0.0, 0.0, /* black */
1.0, 1.0, 0.0, /* yellow */
/* Right face */
/* Bottom left */
1.0, 1.0, 0.0, /* yellow */
1.0, 0.0, 1.0, /* magenta */
0.0, 0.0, 1.0, /* blue */
/* Top right */
1.0, 1.0, 0.0, /* yellow */
0.0, 0.0, 0.0, /* black */
1.0, 0.0, 1.0, /* magenta */
/* Back face */
/* Bottom left */
0.0, 0.0, 0.0, /* black */
0.0, 1.0, 1.0, /* cyan */
1.0, 0.0, 1.0, /* magenta */
/* Top right */
0.0, 0.0, 0.0, /* black */
1.0, 1.0, 1.0, /* white */
0.0, 1.0, 1.0, /* cyan */
/* Bottom face */
/* Bottom left */
0.0, 1.0, 0.0, /* green */
1.0, 0.0, 1.0, /* magenta */
0.0, 1.0, 1.0, /* cyan */
/* Top right */
0.0, 1.0, 0.0, /* green */
0.0, 0.0, 1.0, /* blue */
1.0, 0.0, 1.0, /* magenta */
};
int main(int argc, char **argv) {
EGLDisplay sEGLDisplay;
EGLContext sEGLContext;
EGLSurface sEGLSurface;
/* EGL Configuration */
EGLint aEGLAttributes[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_DEPTH_SIZE, 16,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
EGLint aEGLContextAttributes[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLConfig aEGLConfigs[1];
EGLint cEGLConfigs;
#ifdef _WIN32
MSG sMessage;
#else
XSetWindowAttributes win_attrs;
int attrs[64], idx = 0, num_config = 0;
int major, minor;
Colormap colormap;
XVisualInfo *pVisual;
XEvent e;
#endif
GLint iLocPosition = 0;
GLint iLocColour, iLocTexCoord, iLocNormal, iLocMVP;
GLint iLocXangle, iLocYangle, iLocZangle;
GLint iLocAspect, iLocLightPos, iLocSampler, iLocSampler2;
GLuint uiProgram, uiFragShader, uiVertShader;
GLenum myTex, myTex2;
int bDone = 0;
const unsigned int uiWidth = 640;
const unsigned int uiHeight = 480;
int iXangle = 0, iYangle = 0, iZangle = 0;
float aTBNmatrix1[9], aTBNmatrix2[9];
float aLightPos[] = { 0.0f, 0.0f, -1.0f }; // Light is nearest camera.
unsigned char *myPixels = calloc(1, 128*128*4); // Holds texture data.
unsigned char *myPixels2 = calloc(1, 128*128*4); // Holds texture data.
float aRotate[16], aModelView[16], aPerspective[16], aMVP[16];
int i;
/* EGL Init */
#ifdef _WIN32
hDisplay = GetDC(NULL);
#else
hDisplay = XOpenDisplay(NULL);
#endif
if (!hDisplay) {
printf("Could not open display\n");
exit(-1);
}
sEGLDisplay = EGL_CHECK(eglGetDisplay(hDisplay));
EGL_CHECK(eglInitialize(sEGLDisplay, NULL, NULL));
EGL_CHECK(eglChooseConfig(sEGLDisplay, aEGLAttributes, aEGLConfigs, 1, &cEGLConfigs));
if (cEGLConfigs == 0) {
printf("No EGL configurations were returned.\n");
exit(-1);
}
#ifdef _WIN32
hWindow = create_window(uiWidth, uiHeight);
#else
hWindow = create_window("OpenGL ES 2.0 Example on a Linux Desktop", uiWidth,
uiHeight, hDisplay, sEGLDisplay, aEGLConfigs[0], &colormap, &pVisual);
#endif
sEGLSurface = EGL_CHECK(eglCreateWindowSurface(sEGLDisplay, aEGLConfigs[0], (EGLNativeWindowType)hWindow, NULL));
if (sEGLSurface == EGL_NO_SURFACE) {
printf("Failed to create EGL surface.\n");
exit(-1);
}
sEGLContext = EGL_CHECK(eglCreateContext(sEGLDisplay, aEGLConfigs[0], EGL_NO_CONTEXT, aEGLContextAttributes));
if (sEGLContext == EGL_NO_CONTEXT) {
printf("Failed to create EGL context.\n");
exit(-1);
}
EGL_CHECK(eglMakeCurrent(sEGLDisplay, sEGLSurface, sEGLSurface, sEGLContext));
/* Shader Initialisation */
process_shader(&uiVertShader, "shader.vert", GL_VERTEX_SHADER);
process_shader(&uiFragShader, "shader.frag", GL_FRAGMENT_SHADER);
/* Create uiProgram (ready to attach shaders) */
uiProgram = GL_CHECK(glCreateProgram());
/* Attach shaders and link uiProgram */
GL_CHECK(glAttachShader(uiProgram, uiVertShader));
GL_CHECK(glAttachShader(uiProgram, uiFragShader));
GL_CHECK(glLinkProgram(uiProgram));
/* Get attribute locations of non-fixed attributes like colour and texture coordinates. */
iLocPosition = GL_CHECK(glGetAttribLocation(uiProgram, "av4position"));
iLocColour = GL_CHECK(glGetAttribLocation(uiProgram, "av3colour"));
#ifdef DEBUG
printf("iLocPosition = %i\n", iLocPosition);
printf("iLocColour = %i\n", iLocColour);
#endif
/* Get uniform locations */
iLocMVP = GL_CHECK(glGetUniformLocation(uiProgram, "mvp"));
#ifdef DEBUG
printf("iLocMVP = %i\n", iLocMVP);
#endif
GL_CHECK(glUseProgram(uiProgram));
/* Enable attributes for position, colour and texture coordinates etc. */
GL_CHECK(glEnableVertexAttribArray(iLocPosition));
GL_CHECK(glEnableVertexAttribArray(iLocColour));
/* Populate attributes for position, colour and texture coordinates etc. */
GL_CHECK(glVertexAttribPointer(iLocPosition, 3, GL_FLOAT, GL_FALSE, 0, aVertices));
GL_CHECK(glVertexAttribPointer(iLocColour, 3, GL_FLOAT, GL_FALSE, 0, aColours));
GL_CHECK(glEnable(GL_CULL_FACE));
GL_CHECK(glEnable(GL_DEPTH_TEST));
#ifndef _WIN32
XSelectInput(hDisplay, hWindow, KeyPressMask | ExposureMask | EnterWindowMask
| LeaveWindowMask | PointerMotionMask | VisibilityChangeMask | ButtonPressMask
| ButtonReleaseMask | StructureNotifyMask);
#endif
/* Enter event loop */
while (!bDone) {
#ifdef _WIN32
if(PeekMessage(&sMessage, NULL, 0, 0, PM_REMOVE)) {
if(sMessage.message == WM_QUIT) {
bDone = 1;
} else {
TranslateMessage(&sMessage);
DispatchMessage(&sMessage);
}
}
#else
while (XPending(hDisplay) > 0) {
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Opengl_ES_2.0 的示例代码,是个旋转的方体。可以在仿真器上模拟。 仿真器:OpenGL_ES_2_0_Emulator_1.2.0.5635_Win32.msi 说明: 仿真器安装完毕后 1.把其中的libEGL.lib和libGLESv2.lib拷贝到vs2008的lib库中,例如: C:\Program Files\Microsoft Visual Studio 9.0\VC\lib 2.把其中的include拷贝到vs2008的头文件中。 2.把其中的libEGL.dll和libGLESv2.dll拷贝到C:\WINDOWS\system32下。
资源推荐
资源详情
资源评论
收起资源包目录
opengl es 2.0 demo(vs2008).rar (32个子文件)
cube
cube
shader.frag 451B
matrix.h 696B
cube.c 10KB
shader.h 527B
cube.h 1KB
cube.vcproj 4KB
matrix.c 2KB
shader.vert 523B
window.c 4KB
Debug
cube.obj 36KB
cube.exe.embed.manifest 663B
matrix.obj 8KB
cube.exe.embed.manifest.res 728B
vc90.idb 155KB
window.obj 11KB
BuildLog.htm 9KB
cube.exe.intermediate.manifest 621B
mt.dep 67B
vc90.pdb 68KB
shader.obj 14KB
window.h 865B
cube.vcproj.WWW-87DD92D5B12.Administrator.user 1KB
cube.vcproj.CNHMO.Administrator.user 1KB
shader.c 3KB
cube.suo 17KB
cube.ncb 5.53MB
Debug
cube.ilk 457KB
shader.frag 451B
shader.vert 523B
cube.exe 44KB
cube.pdb 459KB
cube.sln 878B
共 32 条
- 1
keepliving
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页