Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <assert.h>
- #include <math.h>
- #include <GL/freeglut.h>
- #define WindowW 800
- #define WindowH 600
- #define FbW 320
- #define FbH 240
- #define FbTexW 0x200
- #define FbTexH 0x100
- static const float VertexCoord[] = {0, 0, FbTexW, 0, 0, FbTexH, FbTexW, FbTexH};
- static void initGl() {
- glEnable(GL_TEXTURE_2D);
- glEnableClientState(GL_VERTEX_ARRAY);
- glClearColor(0, 0, 0, 0);
- glShadeModel(GL_FLAT);
- glOrtho(0, FbW, FbH, 0, 1, -1);
- glVertexPointer(2, GL_FLOAT, 0, VertexCoord);
- }
- static void resize(int w, int h) {
- int p = w * FbH;
- int q = h * FbW;
- if (p > q) {
- float w_ = (float)q / FbH;
- glViewport((int)roundf((w - w_) * 0.5f), 0, (int)roundf(w_), h);
- } else {
- float h_ = (float)p / FbW;
- glViewport(0, (int)roundf((h - h_) * 0.5f), w, (int)roundf(h_));
- }
- }
- static void draw() {
- glClear(GL_COLOR_BUFFER_BIT);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glutSwapBuffers();
- }
- int main(int argc, char **argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE);
- glutInitWindowSize(WindowW, WindowH);
- glutCreateWindow(argv[0]);
- initGl();
- glutDisplayFunc(draw);
- glutReshapeFunc(resize);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment