У меня проблема в программе, которую я пишу, что шейдеры в соответствии с OpenGL ES 2.0 и EGL не компилируются. Сейчас я много чего перепробовал.
Я сократил материал до небольшого примера:
#include <X11/Xlib.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <stdio.h>
#include <stdlib.h>
Display *x11_disp = NULL;
EGLDisplay display = EGL_NO_DISPLAY;
EGLContext context = EGL_NO_CONTEXT;
EGLConfig config = NULL;
static const GLchar * sFragShader_Rect =
"precision mediump float;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_FragColor = v_color;\n"
"}\n";
static const GLchar * sVertShader_Rect =
"uniform mat4 modelviewProjection;\n"
"attribute vec4 pos;\n"
"attribute vec4 color;\n"
"varying vec4 v_color;\n"
"void main() {\n"
" gl_Position = modelviewProjection * pos;\n"
" v_color = color;\n"
"}\n";
static const GLchar * sFragShader_Texture =
"precision mediump float;\n"
"uniform sampler2D tex;\n"
"varying vec2 v_texcoord;\n"
"void main() {\n"
" gl_FragColor = texture2D(tex, v_texcoord);\n"
"}\n";
static const GLchar * sVertShader_Texture =
"uniform mat4 modelviewProjection;\n"
"attribute vec4 pos;\n"
"attribute vec2 texcoord;\n"
"varying vec2 v_texcoord;\n"
"void main() {\n"
" gl_Position = modelviewProjection * pos;\n"
" v_texcoord = texcoord;\n"
"}\n";
uint32_t FragmentShaderRect = 0;
uint32_t VertexShaderRect = 0;
uint32_t FragmentShaderTexture = 0;
uint32_t VertexShaderTexture = 0;
uint32_t ProgramRext = 0;
uint32_t ProgramTexture = 0;
uint32_t createShader(uint32_t shader_type, const char *source)
{
GLenum error;
GLint status = GL_FALSE;
GLuint shader = glCreateShader(shader_type);
error = glGetError();
if (error != GL_NO_ERROR)
{
printf("Error creating shader.");
return 0;
}
glShaderSource(shader, 1, &source, NULL);
error = glGetError();
if (error != GL_NO_ERROR)
{
printf("Error setting shader source.");
return 0;
}
glCompileShader(shader);
error = glGetError();
if (error != GL_NO_ERROR)
{
printf("Error compiling shader.");
return 0;
}
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status != GL_TRUE)
{
char log[1000] = {};
GLsizei len;
glGetShaderInfoLog(shader, 1000, &len, log);
printf("GL_Error (%d): %s\n", len, log);
}
else
{
printf("Shader compile success.\n");
}
return shader;
}
void initialize()
{
XInitThreads();
x11_disp = XOpenDisplay(NULL);
if (x11_disp == NULL)
{
printf("Error opening display.\n");
exit(-1);
}
display = eglGetDisplay(x11_disp);
if (display == EGL_NO_DISPLAY)
{
printf("Error getting display.\n");
exit(-1);
}
eglInitialize(display, NULL, NULL);
EGLint n_config;
EGLint attributes[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_DEPTH_SIZE, 24,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
if (eglChooseConfig(display, attributes, &config, 1, &n_config) == EGL_FALSE)
{
printf("Error getting config.\n");
exit(-1);
}
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE)
{
printf("Could not bind api.\n");
exit(-1);
}
EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attribs);
if (context == EGL_NO_CONTEXT)
{
printf("Could not create context");
exit(-1);
}
// GLES STUFF
glGetError(); // clear the error
GLenum error;
FragmentShaderRect = createShader(GL_FRAGMENT_SHADER, sFragShader_Rect);
VertexShaderRect = createShader(GL_VERTEX_SHADER, sVertShader_Rect);
FragmentShaderTexture = createShader(GL_FRAGMENT_SHADER, sFragShader_Texture);
VertexShaderTexture = createShader(GL_VERTEX_SHADER, sVertShader_Texture);
}
int main()
{
initialize();
return 0;
}
Компилировать с gcc -o egltest egltest.c -lEGL -lGLESv2 -lX11
Я тоже не получаю сообщение об ошибке.