- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
该项目编译运行,但窗口中没有任何显示。
它应该显示一些文本和一个带有一些点的区域。谁能帮我解决这个问题?
这是我的代码:
#include <stdio.h>
#include <windows.h>
#include <GL/gl.h>
#include <glut.h>
#define KEY_ESCAPE 27
#define PROJECTION_WIDTH 150
#define NUMBER_OF_FLIES 50
float xpos[NUMBER_OF_FLIES];
float ypos[NUMBER_OF_FLIES];
typedef struct {
int width;
int height;
char* title;
float field_of_view_angle;
float z_near;
float z_far;
} glutWindow;
glutWindow win;
// To display the text
void renderBitmapString(float x, float y, void *font, const char *string)
{
const char *c;
glRasterPos3f(x, y, 0);
for (c = string; *c != '\0'; c++)
{
glutBitmapCharacter(font, *c);
}
}
void displayText()
{
glPushMatrix();
//glTranslatef(1.0, 0.50, 0.5);
//const int font = (int)GLUT_BITMAP_9_BY_15;
const int font = (int)GLUT_BITMAP_HELVETICA_12;
glColor3f(0.0f, 0.0f, 0.0f); // black color
renderBitmapString(-1.7, 1.3, (void *)font, "1. Load Measured projections");
renderBitmapString(-1.7, 1.2, (void *)font, "2. Set the position of flies, i.e. create initial guess");
renderBitmapString(-1.7, 1.1, (void *)font, "3. Compute projections from the current reconstruction");
renderBitmapString(-1.7, 1, (void *)font, "4. Compute the population's perfomance, i.e. the global fitness");
renderBitmapString(-1.7, 0.9, (void *)font, "5. Select a random fly (fly_to_kill)");
renderBitmapString(-1.7, 0.8, (void *)font, "6. Remove the fly's contribution");
renderBitmapString(-1.7, 0.7, (void *)font, "7. Compute the population's performance without the selected fly");
renderBitmapString(-1.7, 0.6, (void *)font, "8. Compare the performances, i.e. compute the fly's local fitness");
renderBitmapString(-1.7, 0.5, (void *)font, "9. If the local fitness is equal to or greater than the selection threshold,");
renderBitmapString(-1.5, 0.4, (void *)font, "then go to Step 10, ");
renderBitmapString(-1.5, 0.3, (void *)font, "else go to Step 11");
renderBitmapString(-1.7, 0.2, (void *)font, "10. Restore the fly's contribution, then go to Step 5");
renderBitmapString(-1.7, 0.1, (void *)font, "11. Select a genetic operator");
renderBitmapString(-1.7, 0.0, (void *)font, "12. If the genetic operator is mutation,");
renderBitmapString(-1.5, -0.1, (void *)font, "then go to Step 13, ");
renderBitmapString(-1.5, -0.2, (void *)font, "else go to Step 19 ");
renderBitmapString(-1.7, -0.3, (void *)font, "13. Select a random fly (fly_to_reproduce)");
renderBitmapString(-1.7, -0.4, (void *)font, "14. Remove the fly's contribution");
renderBitmapString(-1.7, -0.5, (void *)font, "15. Compute the population's performance without the selected fly");
renderBitmapString(-1.7, -0.6, (void *)font, "16. Compare the performances, i.e. compute the fly's local fitness");
renderBitmapString(-1.7, -0.7, (void *)font, "17. Restore the fly's contribution'");
renderBitmapString(-1.7, -0.8, (void *)font, "18. If the local fitness is smaller than the selection threshold,");
renderBitmapString(-1.5, -0.9, (void *)font, "then go to Step 13, ");
renderBitmapString(-1.5, -1, (void *)font, "else go to Step 20 ");
renderBitmapString(-1.7, -1.1, (void *)font, "19. Replace fly_to_kill by a new fly with a random position, go to Step 22");
renderBitmapString(-1.7, -1.2, (void *)font, "20. Replace fly_to_kill by a new fly based on fly_to_reproduce");
renderBitmapString(-1.7, -1.3, (void *)font, "21. Add the fly's contribution to the population");
renderBitmapString(-1.7, -1.4, (void *)font, "22. If stop the reconstruction,");
renderBitmapString(-1.5, -1.5, (void *)font, "then go to Step 23, ");
renderBitmapString(-1.5, -1.6, (void *)font, "else go to Step 4 ");
renderBitmapString(-1.7, -1.7, (void *)font, "23. Extract good flies");
// the bottom left
renderBitmapString(-3.9, -0.9, (void *)font, "Iterative paradigm for tomography reconstruction");
renderBitmapString(-3.9, -1, (void *)font, "(click here to view the flowchart in full resolution)");
// the top right
renderBitmapString(1.8, 1.3, (void *)font, "Basic Fly algorithm for tomography reconstruction");
renderBitmapString(1.8, 1.2, (void *)font, "(click here to view the flowchart in full resolution)");
glPopMatrix();
glutSwapBuffers();
}
void displayFlies()
{
glPushMatrix();
//glTranslatef(0.0, 0.50, 0.0);
glColor3f(0.0f, 0.0f, 1.0f); //blue color
glPushAttrib(GL_POINT_BIT);
glPointSize(5.0);
// drawing the data
for (int i = 0; i < NUMBER_OF_FLIES; i++){
int DX = xpos[i];
int DY = ypos[i];
glPushMatrix();
//glTranslatef(- 0.85 + DX * 0.014, -1.2 + DY * 0.0135, 0.0);
glBegin(GL_POINTS); // drawing points
glVertex3f(DX, DY, 0.0f);
glEnd();
glPopMatrix();
}
glPopAttrib();
// draw The display Area
glBegin(GL_LINE_LOOP); //start drawing a line loop
glVertex3f(0.65f, 0.25f, 0.0f); //left of window
glVertex3f(0.65f, -1.20f, 0.0f); //bottom of window
glVertex3f(-0.85f, -1.20f, 0.0f); //right of window
glVertex3f(-0.85f, 0.25f, 0.0f); //top of window
glEnd(); //end drawing of line loop
glPopMatrix();
glutSwapBuffers();
}
void displayProjection()
{
glPushMatrix();
//glTranslatef(1.20, 0.50, 0.0);
// The upper rectangle
glBegin(GL_LINE_LOOP); //start drawing a line loop
glVertex3f(0.65f, 0.60f, 0.0f); //left of window
glVertex3f(0.65f, 0.27f, 0.0f); //bottom of window
glVertex3f(-0.85f, 0.27f, 0.0f); //right of window
glVertex3f(-0.85f, 0.60f, 0.0f); //top of window
glEnd();
//The right rectangle
glBegin(GL_LINE_LOOP); //start drawing a line loop
glVertex3f(0.67f, 0.25f, 0.0f); //left of window
glVertex3f(0.67f, -1.20f, 0.0f); //bottom of window
glVertex3f(0.99f, -1.20f, 0.0f); //right of window
glVertex3f(0.99f, 0.25f, 0.0f); //top of window
glEnd(); //end drawing of line loop
// draw Horizontal RED lines
glBegin(GL_LINES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.25f, 0.60f, 0.0f);
glVertex3f(-0.25f, 0.27f, 0.0f);
glVertex3f(0.1f, 0.27f, 0.0f);
glVertex3f(0.1f, 0.60f, 0.0f);
glEnd();
// draw Upper RED lines
glBegin(GL_LINES);
glVertex3f(0.46f, 0.18f, 0.59f); // origin of the Right line
glVertex3f(0.59f, 0.29f, -0.11f); // ending point of the Right line
glVertex3f(-0.37f, 0.18f, 0.59f); // origin of the Left line
glVertex3f(-0.33f, 0.29f, -0.11f); // ending point of the Left line
glVertex3f(0.37f, 0.40f, 0.92f); // origin of the Upper line
glVertex3f(0.40f, 0.49f, 0.50f); // ending point of the Upper line
glEnd();
// draw Horizontal RED lines
glBegin(GL_LINES);
glVertex3f(-0.06f, 0.47f, -1.50f); // Origin The Upper Horizontal line
glVertex3f(-0.06f, -0.23f, -1.50f); // Ending point of The Upper Horizontal line
glVertex3f(-0.06f, -0.63f, -1.50f); // Origin The bottom Horizontal line
glVertex3f(-0.06f, -1.40f, -1.50f); // Ending point of The bottom Horizontal line
glVertex3f(0.36f, -0.23f, -1.50f); // Origin The right Horizontal line
glVertex3f(0.36f, -0.63f, -1.50f); // Ending point of The right Horizontal line
glVertex3f(0.78f, -0.30f, 0.21f); // origin of the upper vartical line
glVertex3f(0.95f, -0.29f, -0.11f); // ending point of the upper vartical line
glVertex3f(0.78f, -0.60f, 0.21f); // origin of the bottom vartical line
glVertex3f(0.95f, -0.61f, -0.11f); // ending point of the bottom vartical line
glEnd();
glPopMatrix();
}
// intialization function
void initialize()
{
glMatrixMode(GL_PROJECTION); // select projection matrix
glViewport(0, 0, win.width, win.height); // set the viewport
glMatrixMode(GL_PROJECTION); // set matrix mode
glLoadIdentity(); // reset projection matrix
GLfloat aspect = (GLfloat)win.width / win.height;
//gluPerspective(win.field_of_view_angle, aspect, win.z_near, win.z_far); // set up a perspective projection matrix
gluOrtho2D(0, win.width, 0, win.height);
glMatrixMode(GL_MODELVIEW); // specify which matrix is the current matrix
glClearDepth(1.0f); // specify the clear value for the depth buffer
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // specify implementation-specific hints
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // specify clear values for the color buffers"background"
}
// keyboard control function
void keyboard(unsigned char key, int mousePositionX, int mousePositionY)
{
switch (key)
{
case KEY_ESCAPE:
exit(0);
break;
default:
break;
}
}
// the main function
int main(int argc, char **argv)
{
// set window values
win.width = 1350;
win.height = 690;
win.title = " The Project ";
win.field_of_view_angle = 45;
win.z_near = 1.0f;
win.z_far = 500.0f;
//initialing the data
for (int i = 0; i < NUMBER_OF_FLIES; i++){
xpos[i] = rand() % PROJECTION_WIDTH;
ypos[i] = rand() % PROJECTION_WIDTH;
}
// initialize and run program
glutInit(&argc, argv); // GLUT initialization
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Display Mode
glutInitWindowSize(win.width, win.height); // set window size
glutCreateWindow(win.title); // create Window
glutDisplayFunc(displayText); // register Display Function
glutIdleFunc(displayText); // register Idle Function
glutDisplayFunc(displayFlies); // register Display Function
glutIdleFunc(displayFlies);
glutDisplayFunc(displayProjection); // register Display Function
glutIdleFunc(displayProjection);
glutKeyboardFunc(keyboard); // register Keyboard Handler
initialize();
glutMainLoop(); // run GLUT mainloop
return 0;
}
最佳答案
你有三个不同的显示函数,但是 glutDisplayFunc
和 glutIdleFunc
只使用你设置的最新的一个,所以 displayText
和 displayFlies
未使用。
最后一个,displayProjection
,最后需要一行:
glutSwapBuffers();
此外,您可能需要设置一些灯光来照亮您绘制的内容。
顺便说一句,注释掉其他两个,你可以测试 displayFlies
,它呈现一堆蓝点,和 displayText
,它写一些文本(黑色在黑色背景上,几条线相互叠加)。
最好先尝试一些教程,例如NeHe ... 是的,正如其他评论员所说,学习着色器可能会更好 :)
关于c++ - 如何使用 OpenGL/GLUT 显示文本和一些点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31371611/
表架构 DROP TABLE bla; CREATE TABLE bla (id INTEGER, city INTEGER, year_ INTEGER, month_ INTEGER, val I
我需要拆分字符串/或从具有以下结构的字符串中获取更容易的子字符串。 字符串将来自 window.location.pathname 或 window.location.href,看起来像 text/n
每当将对象添加到数组中时,我都会尝试更新 TextView ,并在 TextView 中显示该文本,如下所示: "object 1" "object 2" 问题是,每次将新对象添加到数组时,它都会覆盖
我目前正在寻找使用 Java 读取网站可见文本并将其存储为纯文本字符串的方法。 换句话说,我想转换成这样: Hello stupid World进入“ Hello World ” 或者类似的东西 Un
我正在尝试以文本和 HTML 格式发送电子邮件,但无法正确发送正确的 header 。特别是,我想设置 Content-Type header ,但我找不到如何为 html 和文本部分单独设置它。 这
我尝试了上面的代码,但我无法绑定(bind)文本,我怎样才能将资源内部文本 bloc
我刚刚完成了 Space Shooter 教程,由于没有 GUIText 对象,所以我创建了 UI.Text 对象并进行了相应的编码。它在统一播放器中有效,但在构建 Web 应用程序后无效。我花了一段
我有这个代码: - (IBAction)setButtonPressed:(id)sender { NSUserDefaults *sharedDefaults = [[NSUserDefau
抱歉标题含糊不清,但我想不出我想在标题中做什么。无论如何,对于图像上的文本,我使用了 JLabel 文本并将其添加到图标中。 JLabel icon = new JLabel(new Imag
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我在将 Twitter 嵌入到我从 HTML 5 转换的 wordpress 运行网站时遇到问题。 我遇到的问题是推文不是我的自定义字体... 这是我无法使用任何 css 定位的 HTML 代码,我正
我正在尝试找到解决由于使用以下形式的代码而导致的冗余字符串连接问题的最佳方法: logger.debug("Entering loop, arg is: " + arg) // @1 在大多数情况下,
我写了这个测试 @Test public void removeRequestTextFromRouteError() throws Exception { String input = "F
我目前正在创建一个正则表达式来拆分所有匹配以下格式的字符串:&[文本],并且需要获取文本。字符串可能类似于:something &[text] &[text] everything &[text] 等
有没有办法将标题文本从一个词变形为另一个词,同时保留两个词中使用的字母?我看过的许多 css 文本动画大多是视觉的,很少有旋转整个单词的。 我想要做的是从一个词过渡,例如“BEACH”到“CHANGE
总结matplotlib绘图如何设置坐标轴刻度大小和刻度。 上代码: ?
我在容器 (1) 中创建了容器 (2)。你能帮忙如何向容器(1)添加文本吗?下面是我的代码 return Scaffold( body: Padding( padding: c
我似乎找不到任何人或任何人这样做过。我试图限制我们使用的图像数量,并想创建一个带有渐变作为其“颜色”的文本,并在其周围设置渐变轮廓/描边 到目前为止,我还没有看到任何将两者结合在一起的东西。 我可以自
我正在为视频游戏暗黑破坏神 2 使用 discord.py 构建一个不和谐机器人。其中一项功能要求机器人从暗黑破坏神 2 屏幕截图中提取项目的名称和属性。我目前正在为此使用 pytesseract,但
我很难弄清楚如何旋转 strip.text theme 中的属性来自 ggplot2 .我使用的是 R 版本 3.4.2 和 ggplot2 版本 2.2.1。 以下是 MWE 的数据。 > dput
我是一名优秀的程序员,十分优秀!