- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在编写与 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
编译
我也没有收到错误消息。
最佳答案
基于 Rabbid76 评论:
eglCreateContext
不会使上下文成为当前上下文,您需要在之后调用 eglMakeCurrent
:
context = eglCreateContext(display, config, EGL_NO_CONTEXT, ctx_attribs);
eglMakeCurrent(display, surface, surface, context);
...其中 surface
由 eglCreateWindowSurface
(XWindow) eglCreatePBufferSurface
(或多或少是 OpenGL 帧缓冲区)之一创建,或 eglCreatePixmapSurface
(XPixmap)。
关于c - OpenGL ES 2.0 着色器创建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56124930/
我必须在文本区域上绘制哪些选项? 我认识一些所见即所得的编辑器。我不确定他们使用的方法是什么,并且会看看他们以了解,但我知道像 tinymce 这样的事情已经存在了一段时间,所以我猜现在可能有更现代的
我在我的 woo commerce 商店页面中创建了一个子类别排序菜单。我想将链接到我现在所在页面的链接设置为红色。我对 css 没有问题,只是用 js 脚本。我怎样才能让它突出当前?这是我创建的排序
所以我使用 TextWrangler4.5.3 并主要使用 Python 编写脚本。当我编写 Python 时,我经常喜欢发表类似这样的评论:# BEGINS foo 然后是 # ENDS foo 我
我需要你的帮助! 我有一个表格,里面有行(姓名等)现在,当位于该行上的对象具有特定值时,我想为特定的 tableCells 背景着色。但我只得到它来读取这个单元格的值。但我需要阅读对象(在我的代码中称
有人知道在 uikit 中给 uiactionsheet 着色吗? 最佳答案 是的,因为它是一个 UIView(如 kmit 所述),您可以使用以下命令:addSubview,因此您可以添加自己的背景
在 vba 中,我想从工作表中的单元格中读取颜色来为条形图中的特定条形着色。我的问题是我的颜色格式为 4F9F92,但要在 makro 中读取它,我需要使用单元格中的 excel 颜色代码 40762
我正在尝试绘制一个 geom_histogram,其中条形图由渐变着色。 这就是我想要做的: library(ggplot2) set.seed(1) df <- data.frame(id=past
我正在构建一个带有 shiny 的应用程序,并使用与 Shiny gallery ( http://shiny.rstudio.com/gallery/slider-bar-and-slider-ra
在 iOS 6 和 xcode 4 中,我有这个: https://dl.dropboxusercontent.com/u/60718318/photo.PNG使用代码可以轻松创建 [editButt
我正在向我的 iPhone UI 添加自定义按钮,并希望使它们具有 Apple 应用程序中的玻璃外观。我有一个很好的默认玻璃图像,但我不想为我想要的每种色调(红色、绿色、蓝色等)都有一个单独的图像。
我到处寻找但没有找到解决方案。我有图像 1。如何以编程方式使用渐变对它们进行着色以获得图像 2 和 3?以下是这些图像: 我通过 Photoshop 应用到它们的色调是简单的 2 色线性渐变。 我的问
有没有办法告诉 OS X 自动设置 NSToolbarItem 的样式/色调? 我通过 IB/Xcode 添加了一个“图像工具栏项”,并将图标设置为黑色 PDF as described in the
我试图区分列范围图表上的多种类型的数据。问题是我希望能够按多个标准对它们进行分组。 我可以轻松地为不同的列着色,从而解决一个问题,但我希望能够根据我传递到图表的数据,为 xAxis 上的类别(图表是倒
有人在编译模式 Emacs 中添加了对 ansi-color 的支持吗?如果是这样,颜色写入程序必须检查什么属性/属性才能确保其事件终端支持 ANSI 转义着色。 最佳答案 已经有一个函数可以将颜色应
我正在尝试实现 Phong 着色模型,但我不确定如何选择光源。更具体地说,我不明白光源应该是什么样子。它应该是vec3吗?或者也许是我在 Java 代码中定义的矩阵?另外,如果我们假设我希望相机作为光
我有 2 个 dhtmlxSidebars,就像示例中一样 here如何为嵌套背景设置不同的背景颜色?如果我添加CSS .dhxsidebar_side { background-color:
我有一个 JTable,每行都根据最后一列中的值着色。 但是,当我单击标题对行进行排序时,颜色不会跟随行。 我尝试在 JTable 鼠标退出事件上调用我的“colourTable”方法(我知道 Hac
geom_hline 似乎忽略了美观,我错过了什么还是这是一个错误? df session 信息: R version 3.4.4 (2018-03-15) Platform: x86_64-pc-
这个问题已经有答案了: How to draw a BufferedImage with a color tint (1 个回答) 已关闭 8 年前。 如何将通过此处的图标着色为不同的颜色?假设我想拍
我想为除我点击的那个之外的所有 div 着色。在我的代码中它有效,但只有一次。如果我点击另一个 div,它不起作用。 http://jsfiddle.net/6VhK8/353/ id="1
我是一名优秀的程序员,十分优秀!