123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include <stdio.h>
- #include <GLFW/glfw3.h>
- int main (int argc, char** argv)
- {
- GLFWwindow* window;
- if (!glfwInit()) {
- fprintf(stderr, "could not init glfw.\n");
- return 1;
- }
- window = glfwCreateWindow(640, 480, "Hello Window", NULL, NULL);
- if (!window) {
- fprintf(stderr, "could not initialize glfw window\n");
- return 1;
- }
-
- glfwMakeContextCurrent(window);
-
- unsigned char* data = new unsigned char [100 * 100 * 3];
- for (int y=0; y < 100; y++) {
- for (int x = 0; x < 100; x++) {
- data[y * 100 * 3 + x * 3] = 0xff;
- data[y * 100 * 3 + x * 3 + 1] = 0x00;
- data[y * 100 * 3 + x * 3 + 2] = 0x00;
- }
- }
- GLuint texture_handle;
- glGenTextures(1, &texture_handle);
- glBindTexture(GL_TEXTURE_2D, texture_handle);
- glTexImage2D(texture_handle, 0, GL_RGB, 100, 100, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
-
- while (!glfwWindowShouldClose(window)) {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glDrawPixels(100, 100, GL_RGB, GL_UNSIGNED_BYTE, data);
- int window_width, window_height;
- glfwGetFramebufferSize(window, &window_width, &window_height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, window_width, 0, window_height, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, texture_handle);
- glBegin(GL_QUADS);
- glTexCoord2d(0,0);glTexCoord2d(0,0);
- glTexCoord2d(1,0);glTexCoord2d(100,0);
- glTexCoord2d(1,1);glTexCoord2d(100,100);
- glTexCoord2d(0,1);glTexCoord2d(0,100);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- glfwSwapBuffers(window);
- glfwWaitEvents();
- }
- return 0;
- }
|