2
我能夠得出使用OpenGL一條線,這將產生以下結果:如何繪製鋸齒狀像素化線的OpenGL
然而,這一行看起來光滑,相比於外的地方我的遊戲的像素化風格。我希望能有一個結果看上去更像是這樣的:
可有人請給我我怎樣才能得到的OpenGL繪製這樣的像素化線有什麼祕訣?
這裏是我的renderLine()方法(使用即時模式,恐怕):
public static void renderLine(float x1, float y1, float x2, float y2,
float thickness, float[] colour) {
// Store model matrix to prevent contamination
glPushMatrix();
// Set colour and thickness
glColor4f(colour[0], colour[1], colour[2], colour[3]);
glLineWidth(thickness);
// Draw line
glBegin(GL_LINES);
{
glVertex2f(x1, y1);
glVertex2f(x2, y2);
}
glEnd();
// Restore previous state
glColor4f(1, 1, 1, 1);
glLineWidth(1.0f);
glPopMatrix();
}
這種方法的問題是我的遊戲中的實體不一定與遊戲世界的渲染像素對齊。它們可以定位在「像素之間」像素之間,與只限於像素網格相比,可以實現更平滑的運動。如果我將整個遊戲以像素完美的方式渲染到更小的紋理上,我會失去這種額外的精度。但是,我可能可以將這種方法用於線渲染 - 謝謝! – Dan
@Dan:您仍然可以在着色器中使用該方法。 – ybungalobill