Advertisement
Guest User

Texture.cpp

a guest
Mar 9th, 2011
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. // OpenGL1_1_glut_init.cpp : Defines the entry point for the console application.
  2.  
  3. //
  4.  
  5.  
  6.  
  7. #include "GLee.h"
  8.  
  9. #include <GL/glut.h>
  10.  
  11. #include <SOIL.h>
  12.  
  13.  
  14.  
  15. #include "Vertices.h"
  16.  
  17.  
  18.  
  19. void render();
  20.  
  21.  
  22.  
  23. GLuint tex = 0;
  24.  
  25.  
  26.  
  27. int main(int argc, char* argv[])
  28.  
  29. {
  30.  
  31.     glutInit(&argc, argv);
  32.  
  33.     glutInitWindowPosition(0, 0);
  34.  
  35.     glutInitWindowSize(800, 600);
  36.  
  37.     glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);
  38.  
  39.  
  40.  
  41.     glutCreateWindow("OGL application");
  42.  
  43.  
  44.  
  45.     glutDisplayFunc(render);
  46.  
  47.  
  48.  
  49.     tex = SOIL_load_OGL_texture("tex1.png", 4, 0, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS);
  50.  
  51.  
  52.  
  53.     glBindTexture(GL_TEXTURE_2D, tex);
  54.  
  55.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  56.  
  57.     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
  58.  
  59.     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
  60.  
  61.  
  62.  
  63.     glutMainLoop();
  64.  
  65.  
  66.  
  67.     return 0;
  68.  
  69. }
  70.  
  71.  
  72.  
  73. void render()
  74.  
  75. {
  76.  
  77.     glClearColor(0, 0, 0, 1);
  78.  
  79.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  80.  
  81.  
  82.  
  83.     glDisable(GL_CULL_FACE);
  84.  
  85.     glFrontFace(GL_CCW);
  86.  
  87.     glCullFace(GL_BACK);
  88.  
  89.  
  90.  
  91.     glColor4f(1, 1, 1, 1);
  92.  
  93.     glBindTexture(GL_TEXTURE_2D, tex);
  94.  
  95.     glEnable(GL_TEXTURE_2D);
  96.  
  97.  
  98.  
  99.     glEnableClientState(GL_VERTEX_ARRAY);
  100.  
  101.     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  102.  
  103.  
  104.  
  105.     glVertexPointer(3, GL_FLOAT, 0, vertices);
  106.  
  107.     glTexCoordPointer(2, GL_FLOAT, 0, uvs);
  108.  
  109.     glDrawArrays(GL_TRIANGLES, 0, 6);
  110.  
  111.  
  112.  
  113.     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  114.  
  115.     glDisableClientState(GL_VERTEX_ARRAY);
  116.  
  117.  
  118.  
  119.     glFlush(); // potrzebne w GLUT
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement