作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个高性能的2D程序。
我正在使用VC++ 2008。假设我已经创建了主窗口。我想要的是在主窗口的工作区中绘制一个红色矩形(左上角:10,20,右下角:200、300),就像FillRect()API所做的一样,但使用的是OpenGL。
void InitOpenGL(HWND hwnd)
{
.... // What should I do?
// Only for 2D drawing, and the (0,0) should be the top left point.
}
// the function below will be called in the WM_PAINT handler
void DrawRectWithOpenGL(RECT* pRect)
{
.... // What should I do?
}
最佳答案
我强烈建议您看一些OpenGL教程(http://nehe.gamedev.net/是一个很好的网站,它会告诉您所有您需要知道的内容),但是假设您在代码中正确设置了OpenGL,则可以在您的DrawRectWithOpenGL函数(我不是C++程序员,但我认为我的代码适合C++):
void DrawRectWithOpenGL(RECT* pRect)
{
glPushMatrix(); //Make sure our transformations don't affect any other transformations in other code
glTranslatef(pRect->x, pRect->y, 0.0f); //Translate rectangle to its assigned x and y position
//Put other transformations here
glBegin(GL_QUADS); //We want to draw a quad, i.e. shape with four sides
glColor3f(1, 0, 0); //Set the colour to red
glVertex2f(0, 0); //Draw the four corners of the rectangle
glVertex2f(0, pRect->h);
glVertex2f(pRect->w, pRect->h);
glVertex2f(pRect->w, 0);
glEnd();
glPopMatrix();
}
glClearColor(0.0, 0.0, 0.0, 0.0); //Set the cleared screen colour to black
glViewport(0, 0, screenwidth, screenheight); //This sets up the viewport so that the coordinates (0, 0) are at the top left of the window
//Set up the orthographic projection so that coordinates (0, 0) are in the top left
//and the minimum and maximum depth is -10 and 10. To enable depth just put in
//glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenwidth, screenheight, 0, -10, 10);
//Back to the modelview so we can draw stuff
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); //Clear the screen and depth buffer
关于opengl - 想要一个OpenGL 2D示例(VC++,绘制一个矩形),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5877728/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!