我正在使用Xcode 5在运行10.9的mac上关注wikibooks上的freetype教程.我使用着色器版本120运行但是我想使用一些现代功能,所以我将SDL提示设置为OpenGL 3.2并将我的着色器转换为150.问题出在版本150中,使用texture2D将阻止着色器编译.
以下是着色器的版本120:
const GLchar* vTextSource =
"#version 120\n"
"attribute vec4 coord;"
"varying vec2 texcoord;"
"void main(void) {"
" gl_Position = vec4(coord.xy, 0, 1);"
" texcoord = coord.zw;"
"}";
const GLchar* fTextSource =
"#version 120\n"
"varying vec2 texcoord;"
"uniform sampler2D tex;"
"uniform vec4 color;"
"void main(void) {"
" gl_FragColor = vec4(1,1,0, texture2D(tex, texcoord).a) * color;"
"}";
Run Code Online (Sandbox Code Playgroud)
这就是我对版本150所拥有的.顶点着色器构建但片段着色器失败,除非我删除了texture2D的任何用途.它们之间的所有CPU代码都是相同的.
const GLchar* vTextSource =
"#version 150 \n"
"in vec4 coord;"
"out vec2 texcoord;"
"void main(void) {"
" gl_Position = vec4(coord.xy, 0, 1);" …Run Code Online (Sandbox Code Playgroud) 我很困惑如何在不同的多个程序之间正确切换.我把问题缩小到以下几点:如果我用NO_HDR运行,它运行正常; 我得到了一些线,太空船和一些球,按顺序渲染.如果我使用HDR运行,我会得到大部分相同的东西,但不是球体,我得到2d正方形.
我认为来自hdr部分的四重顶点属性会覆盖在forwardRender()部分中渲染的最后一些内容.如果我在forwardRender()中更改顺序,则在forwardRender()中最后呈现的内容将以某种方式搞砸.我错过了什么,允许四边形顶点覆盖我的其他对象?
#if NO_HDR
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
forwardRender();
#else
//set to render to custom frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, rt.FramebufferName);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
forwardRender();
//now switch to render to screen
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rt.renderedTexture);
glUseProgram(hdr.shaderProgram);
glUniform1i(texID, 0);
glBindBuffer(GL_ARRAY_BUFFER, hdr.quad_vertexbuffer);
glEnableVertexAttribArray(hdr.quad_vertexPosition_modelspace);
glVertexAttribPointer(
hdr.quad_vertexPosition_modelspace, // attribute
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*)0 // array buffer offset
);
// Draw the triangles !
glBindVertexArray(hdr.vao);
glDrawArrays(GL_TRIANGLES, 0, 6); // …Run Code Online (Sandbox Code Playgroud) 我试图创建一个模板对象的矢量矢量.当我尝试调整内部向量的大小时,错误发生,我无法做出错误消息的头部或尾部.我不知道从何处获取HashTable :: Item :: Item.有什么建议?
/usr/include/c++/4.4.6/bits/stl_vector.h(552):错误:没有构造函数的实例"HashTable :: Item :: Item [with Key = int,Value = Varvalue]"匹配参数列表调整大小(size_type __new_size,value_type __x = value_type())
Run Code Online (Sandbox Code Playgroud)detected during: instantiation of "void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type={size_t={unsigned long}}, std::vector<_Tp, _Alloc>::value_type) [with _Tp=HashTable<int, Varvalue>::Item, _Alloc=std::allocator<HashTable<int, Varvalue>::Item>]" at line 118 of "main.cc"
这是相关代码:
#define VECLEN 16
class Varvalue
{
public:
char data[32];
};
template
class HashTable
{
private:
class Item
{
public:
bool valid;
Key key;
Value value;
Item *next;
Item(const Key k, const Value v, Item *b = 0, bool …