📜 ⬆️ ⬇️

OpenGL ES 2.0 Development in Visual Studio C ++

First question. What for?

Debugging Android NDK is tricky, debugging in Xcode solves 90% of problems. But there is a need to have a prototype game in Win32. For example, to let the designer update the texture in the game and see the result, or to make a video game or a level editor can have a common code with the game and use OpenGL ES 2.0 to display the level, or you do not have Xcode or just you are a Visual Studio fan.

How?

AngleProject code.google.com/p/angleproject provides the OpenGL ES 2.0 API using DirectX. To compile ANGLE you need the DirectX SDK. The latest available DirectX SDK June 2010 is not installed on a modern system. Error S1023 pops up. Uninstall Visual C ++ 2010 Redistributable Package before installation
MsiExec.exe /passive /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5} MsiExec.exe /passive /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7} 

Restart the computer and install the DirectX SDK, now you can compile ANGLE and examples.

The last step is to make a clean project that will compile OpenGL ES 2.0 and contain only compiled libEGL.dll, libGLESv2.dll

In Linker - Input - Additional Dependencies add
 esUtil.lib libEGL.lib libGLESv2.lib 

libEGL.dll, libGLESv2.dll copy to the Debug, Release folders
')
esUtil.lib is a library used by OpenGL ES 2.0 ANGLE examples. Perhaps you do not need it.

Result

If you trust people on the Internet, then you can download a finished project that runs OpenGL ES 2.0 code from Visual Studion 2010 in Windows and does not require installation of the DirectX SDK for compilation.

When you run this example, you will see a window with a triangle



This is the result of the following program.
OpenGL ES 2.0 example draws a triangle
 // // Book: OpenGL(R) ES 2.0 Programming Guide // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner // ISBN-10: 0321502795 // ISBN-13: 9780321502797 // Publisher: Addison-Wesley Professional // URLs: http://safari.informit.com/9780321563835 // http://www.opengles-book.com // // Hello_Triangle.c // // This is a simple example that draws a single triangle with // a minimal vertex/fragment shader. The purpose of this // example is to demonstrate the basic concepts of // OpenGL ES 2.0 rendering. #include <stdlib.h> #include "esUtil.h" typedef struct { // Handle to a program object GLuint programObject; } UserData; /// // Create a shader object, load the shader source, and // compile the shader. // GLuint LoadShader ( GLenum type, const char *shaderSrc ) { GLuint shader; GLint compiled; // Create the shader object shader = glCreateShader ( type ); if ( shader == 0 ) return 0; // Load the shader source glShaderSource ( shader, 1, &shaderSrc, NULL ); // Compile the shader glCompileShader ( shader ); // Check the compile status glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled ); if ( !compiled ) { GLint infoLen = 0; glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen ); if ( infoLen > 1 ) { char* infoLog = malloc (sizeof(char) * infoLen ); glGetShaderInfoLog ( shader, infoLen, NULL, infoLog ); esLogMessage ( "Error compiling shader:\n%s\n", infoLog ); free ( infoLog ); } glDeleteShader ( shader ); return 0; } return shader; } /// // Initialize the shader and program object // int Init ( ESContext *esContext ) { UserData *userData = esContext->userData; GLbyte vShaderStr[] = "attribute vec4 vPosition; \n" "void main() \n" "{ \n" " gl_Position = vPosition; \n" "} \n"; GLbyte fShaderStr[] = "precision mediump float;\n"\ "void main() \n" "{ \n" " gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n" "} \n"; GLuint vertexShader; GLuint fragmentShader; GLuint programObject; GLint linked; // Load the vertex/fragment shaders vertexShader = LoadShader ( GL_VERTEX_SHADER, vShaderStr ); fragmentShader = LoadShader ( GL_FRAGMENT_SHADER, fShaderStr ); // Create the program object programObject = glCreateProgram ( ); if ( programObject == 0 ) return 0; glAttachShader ( programObject, vertexShader ); glAttachShader ( programObject, fragmentShader ); // Bind vPosition to attribute 0 glBindAttribLocation ( programObject, 0, "vPosition" ); // Link the program glLinkProgram ( programObject ); // Check the link status glGetProgramiv ( programObject, GL_LINK_STATUS, &linked ); if ( !linked ) { GLint infoLen = 0; glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen ); if ( infoLen > 1 ) { char* infoLog = malloc (sizeof(char) * infoLen ); glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog ); esLogMessage ( "Error linking program:\n%s\n", infoLog ); free ( infoLog ); } glDeleteProgram ( programObject ); return FALSE; } // Store the program object userData->programObject = programObject; glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); return TRUE; } /// // Draw a triangle using the shader pair created in Init() // void Draw ( ESContext *esContext ) { UserData *userData = esContext->userData; GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f }; // Set the viewport glViewport ( 0, 0, esContext->width, esContext->height ); // Clear the color buffer glClear ( GL_COLOR_BUFFER_BIT ); // Use the program object glUseProgram ( userData->programObject ); // Load the vertex data glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices ); glEnableVertexAttribArray ( 0 ); glDrawArrays ( GL_TRIANGLES, 0, 3 ); eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); } int main ( int argc, char *argv[] ) { ESContext esContext; UserData userData; esInitContext ( &esContext ); esContext.userData = &userData; esCreateWindow ( &esContext, TEXT("Hello Triangle"), 320, 240, ES_WINDOW_RGB ); if ( !Init ( &esContext ) ) return 0; esRegisterDrawFunc ( &esContext, Draw ); esMainLoop ( &esContext ); } 


Successful OpenGL ES 2.0 coding!

Source: https://habr.com/ru/post/199396/


All Articles