我会尝试用图像解释我的问题.所以这是我用于OpenGL应用程序的测试纹理:

正如您所看到的,图像周围有一个2像素宽的边框,不同的颜色让我能够看到我的应用程序中是否正确设置了坐标.
我正在使用9格单元格,所以我用特定的纹理坐标绘制了9个四边形.乍一看一切正常,但显示纹理有一个小问题:

在图片中,我标记的是第一个四边形,第二个在哪里.正如你所看到的,第一个正确显示,但第二个平滑地从第一个四边形颜色到它自己的颜色,但它应该从纯绿色和粉红色开始.所以我猜它是纹理坐标的问题.
这是他们的设置方式:
// Bottom left quad [1st quad]
glBegin(GL_QUADS);
// Bottom left
glTexCoord2f(0.0f, 1.0);
glVertex2i(pos.x, pos.y + height);
// Top left
glTexCoord2f(0.0f, (GLfloat)1.0 - maxTexCoordBorderY);
glVertex2i(pos.x, pos.y + height - m_borderWidth);
// Top right
glTexCoord2f(maxTexCoordBorderX, (GLfloat)1.0 - maxTexCoordBorderY);
glVertex2i(pos.x + m_borderWidth, pos.y + height - m_borderWidth);
// Bottom right
glTexCoord2f(maxTexCoordBorderX, 1.0);
glVertex2i(pos.x + m_borderWidth, pos.y + height);
glEnd();
// Bottom middle quad [2nd quad]
glBegin(GL_QUADS);
// Bottom left
glTexCoord2f(maxTexCoordBorderX, 1.0);
glVertex2i(pos.x + m_borderWidth, pos.y + height);
// …Run Code Online (Sandbox Code Playgroud) 可能重复:
异常始终为NULL
我有一个IOException对象的奇怪问题,但无法找到答案.
代码如下所示:
try { // This isn't very important part, but maybe it has something to do with a problem
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
Log.e(ParseJSON.class.toString(), "Failed to download file");
}
} catch (IOException e) {
System.out.println("I'm here …Run Code Online (Sandbox Code Playgroud) 这是我用来在程序中绘制矩形的代码:
glBegin(GL_QUADS);
glTexCoord2f(0.0f, maxTexCoordHeight); glVertex2i(pos.x, pos.y + height);
glTexCoord2f(0.0f, 0.0f); glVertex2i(pos.x, pos.y);
glTexCoord2f(maxTexCoordWidth, 0.0f); glVertex2i(pos.x + width, pos.y);
glTexCoord2f(maxTexCoordWidth, maxTexCoordHeight); glVertex2i(pos.x + width, pos.y + height);
glEnd();
Run Code Online (Sandbox Code Playgroud)
它只绘制一个具有指定纹理的简单矩形,例如: 
我想问一下OpenGL是否可以实现这样的边框效果:

正如你在这个瓷砖里面看到的那样,只有一个纯蓝色背景可以单独处理 - 只需自动调整纹理大小.这可以通过我给出的代码片段轻松实现,但问题在于边框.
如果边框应该是一种颜色,我可以尝试使用GL_LINES我的纹理周围绘制空的,未填充的矩形,但事实并非如此.
此外,如果瓷砖总是具有固定的尺寸,我可以准备一个与之匹配的纹理,但是它们必须易于调整,而不必更改我用作纹理的位图文件.
因此,如果基本的OpenGL功能无法实现,那么实现这种效果最有效和/或最简单的方法是什么?
编辑:它必须是2D.
在我的应用程序中,我收到此错误:
HEAP[App.exe]: HEAP: Free Heap block 61af0f0 modified at 61af194 after it was freed
Run Code Online (Sandbox Code Playgroud)
这是一个调用堆栈:
ntdll.dll!_RtlpBreakPointHeap@4() Unknown
ntdll.dll!@RtlpAllocateHeap@24() Unknown
ntdll.dll!_RtlAllocateHeap@12() Unknown
ntdll.dll!_RtlDebugAllocateHeap@12() Unknown
ntdll.dll!@RtlpAllocateHeap@24() Unknown
ntdll.dll!_RtlAllocateHeap@12() Unknown
> msvcr110d.dll!_heap_alloc_base(unsigned int size) Line 57 C
msvcr110d.dll!_heap_alloc_dbg_impl(unsigned int nSize, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 431 C++
msvcr110d.dll!_nh_malloc_dbg_impl(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine, int * errno_tmp) Line 239 C++
msvcr110d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse, const char * …Run Code Online (Sandbox Code Playgroud) c++ memory memory-leaks heap-corruption visual-leak-detector
我为其值类型定义了一个带有模板的Node类
template<class T>
class Node {
T val;
public:
Node (T & v) : val (v) {}
...
void print() { cout << v << endl; }
}
Run Code Online (Sandbox Code Playgroud)
大多数情况下,感兴趣的节点值将是一个对象类class Foo.在这种情况下,使用Node<Foo *>会更方便.但也可能是节点将保持原始时间int.然后使用Node<int>就足够了.
问题是,根据是否T是指针类型,某些函数可能需要表现不同.例如,print应该cout << *v在何时以及cout << v其他方面.
我试过的是定义两者:
template<class T>
class Node {
T val;
public:
Node (T & v) : val (v) {}
...
void print() { cout << v << endl; }
} …Run Code Online (Sandbox Code Playgroud) 我glScissor()在我的应用程序中使用它并且它正常工作,但我遇到了一个问题:我的Window对象是指定了绘图区域glScissor(),在此区域内,我正在绘制我的ListView对象,绘图区域也应该用glScissor()因为我不想把它全部画出来.
在代码中,我可以将其表示为:
Window::draw()
{
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, width, height);
// Draw some components...
mListView.draw(); // mListView is an object of ListView type
glDisable(GL_SCISSOR_TEST);
}
ListView::draw()
{
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, width, height);
// Draw a chosen part of ListView here
glDisable(GL_SCISSOR_TEST);
}
Run Code Online (Sandbox Code Playgroud)
但当然在这种情况下启用/禁用调用是错误的:
glEnable(GL_SCISSOR_TEST);
glEnable(GL_SCISSOR_TEST);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_SCISSOR_TEST);
Run Code Online (Sandbox Code Playgroud)
如果我删除那些内部glEnable/glDisable调用(ListView中的调用),我最终会得到两个glScissor()调用,这似乎也是错误的.
我想以某种方式实现两种剪刀效果,我的意思是 - Window应该只在它的剪切区域中绘制,内部ListView也只在它的剪切区域中绘制.
正如你在图片中看到的那样,红色矩形我标记了剪刀区域,Window其中有一个蓝色矩形,我标记了一个我想要绘制的区域ListView.这就是我试图使用嵌套剪刀的原因,但我知道它没用.基本上我的问题是,实现这一目标的最佳方法是什么?

I'm working on a Tile-based OpenGL, C++ application. I'm adding sample screen from application, so that it will be more clear:

I have Tile class which contains an array of Objects. Each tile can store up to 15 objects - the example of that is Tile with green and yellow square on it (two objects), so it's 10x10x15 = 1500 Objects to draw (in the worst case, because I'm not handling 'empty' ones). Usually it's less, in my …
我创建我的C++应用程序GUI和我有一个叫做类GUIObject是基类的所有其他部件,例如像Button,CheckBox,Window等等.
我也有一个类GUIObjectsStorage,它由GUIObject创建的所有s 组成.到目前为止,我一直在使用原始指针,所以我只是为GUIObject类提供了这个构造函数:
GUIObject::GUIObject() :
{
GUIObjectsStorage::Instance().addObject(this);
}
Run Code Online (Sandbox Code Playgroud)
它可以满足我的需求,因为无论何时我想访问特定对象,我都是从中获取的GUIObjectsStorage.但现在我正在尝试使用智能指针,所以GUIObjectsStorage现在存储数组std::shared_ptr<GUIObject>而不是原始指针,我不能使用我之前使用过的构造函数:
GUIObject::GUIObject() :
{
GUIObjectsStorage::Instance().addObject(std::shared_ptr<GUIObject>(this));
}
Run Code Online (Sandbox Code Playgroud)
因为例如:
// Somewhere in code
std::shared_ptr<Button> bt = std::shared_ptr<Button>(new Button());
Run Code Online (Sandbox Code Playgroud)
基本上我现在有两个shared_ptrs(一个在这里,第二个GUIObjectsStorage,因为它是在Button构造函数中添加的),它们都有引用count = 1,但它们都指向内存中的同一个对象.然后,如果其中一个死亡,对象本身也会被破坏.
所以我提出了一个想法,可能为所有继承自的类GUIObject创建私有构造函数,并创建一个静态方法,该方法将创建并返回std::shared_ptr并将其复制添加到GUIObjectsStorage.这样我可以shared_ptr使用引用count = 2这是正确的:
class Button : public GUIObject
{
private:
// ...
Button();
public:
// ...
static std::shared_ptr<Button> create(); …Run Code Online (Sandbox Code Playgroud) 我有这个URL:http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world
当我把它放到浏览器的地址栏并点击回车时,我得到了带有"Hello world"的综合语音的mp3文件.一切都是正确的.
但现在我在HTML中有一个重定向到此URL的链接,如下所示:
<a href="http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=Hello+world">Link</a>
Run Code Online (Sandbox Code Playgroud)
当我单击此链接时,我没有收到文件但是出现错误(简单的QuickTime徽标).任何人都可以解释我为什么会这样,我怎样才能解决我的问题?
我有9个由三角形组成的四边形,如下所示:

我正在使用它VBO来存储有关它们的数据 - 它们的位置和纹理坐标.
我的问题是 - 是否可以通过仅使用一个VBO和四个来使四边形5具有与其他四边形不同的纹理shader?:

绿色代表纹理1和黄色 - 纹理2.
到目前为止我得到了:
GLfloat vertices[] = {
// Positions
0.0f, 0.0f,
...
// Texture coordinates
0.0f, 0.0f,
...
};
Run Code Online (Sandbox Code Playgroud)
我正在VBO使用该vertices[]数组创建,然后我绑定我的第一个纹理m_texture1(我也可以访问第二个 - m_texture2)并调用着色器:
glBindTexture(GL_TEXTURE_2D, m_texture1);
glUseProgram(program);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboId); // for vertex coordinates
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); // Vertices
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(GLfloat)*108)); // Texture
glDrawArrays(GL_TRIANGLES, 0, 108);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glUseProgram(0);
Run Code Online (Sandbox Code Playgroud)
我的顶点着色器:
#version 330
layout …Run Code Online (Sandbox Code Playgroud)