#define GLUT_NO_LIB_PRAGMA
#pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */
#pragma comment (lib, "glut64.lib") /* link with Win64 GLUT lib */
#include <stdlib.h>
#include "glut.h"
#include "glext.h"
#define WIDTH 512
#define HEIGHT 512
unsigned char *Pixels;
void Draw(void) {
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawPixels(WIDTH, HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, Pixels);
glFlush();
}
int main() {
Pixels = (unsigned char*)malloc(WIDTH*HEIGHT * sizeof(unsigned char) * 4);
for (int i = 0; i < WIDTH; i++) {
for (int j = 0; j < HEIGHT; j++) {
int offset = (WIDTH*i + j) * 4;
Pixels[offset + 0] = 255;
Pixels[offset + 1] = 0;
Pixels[offset + 2] = 0;
Pixels[offset + 3] = 0;
}
}
int argc = 0; char *argv = const_cast<char*>("");
glutInit(&argc, &argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("bitmap");
glutDisplayFunc(Draw);
glutMainLoop();
}
《一周学完光线追踪》学习 一 建立工程文件
最新推荐文章于 2024-04-21 16:14:29 发布