Advertisement
Guest User

Linking GLEW/GLFW with Visual Studio 2013 Express C++

a guest
Aug 27th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.77 KB | None | 0 0
  1. /*
  2. Adam Lastowka
  3.  
  4. Linking GLEW/GLFW with Visual Studio 2013 Express C++
  5.  
  6. 1. Download GLEW and the Win32 GLFW binaries (even if you have a 64-bit OS!!) and unzip. Put in an easily accessible folder (I put mine in a folder called VS_DEV_LIB)
  7.  
  8. 2. Open Visual Studio and make a new empty C++ project.
  9.  
  10. 3. Right click on the project (not the solution) in the solution explorer and go to properties.
  11.  
  12. 4. In the upper left hand corner of the properties tab, switch the configuration to All Configurations.
  13.  
  14. 5. Under Configuration Properties->VC++ Directories, add the following to Include Directories:
  15.     VS_DEV_LIB\glfw-3.0.4.bin.WIN32\include
  16.     VS_DEV_LIB\glew-1.10.0-win32\include
  17. Then add the following to Library Directories:
  18.     VS_DEV_LIB\glfw-3.0.4.bin.WIN32\lib-msvc120
  19.     VS_DEV_LIB\glew-1.10.0-win32\lib
  20.  
  21. 6. Under Configuration Properties->Linker->Input, add the following to Additional Dependencies:
  22.     opengl32.lib
  23.     glu32.lib
  24.     glew32.lib
  25.     glfw3.lib
  26.  
  27. 7. Put glew32.dll into the folder with your .vcxproj file (Visual Studio 2013\Projects\OpenGLTest\OpenGLTest\).
  28.  
  29. 8. You are now done! Test your project’s link with this code:
  30.  
  31. */
  32.  
  33. //Include GLEW  
  34. #include <GL/glew.h>  
  35.  
  36. //Include GLFW  
  37. #include <GLFW/glfw3.h>  
  38.  
  39. //Include the standard C++ headers  
  40. #include <stdio.h>  
  41. #include <stdlib.h>
  42.  
  43. //Printing stuff ya'know
  44. #include <iostream>
  45.  
  46. //Yay math
  47. #include <math.h>
  48.  
  49. double tickNum = 0.0;
  50.  
  51. int resSX;
  52. int resSY;
  53.  
  54. void setProjections() {
  55.     glViewport(0, 0, resSX, resSY);
  56.     glLoadIdentity();
  57. }
  58.  
  59. int main() {
  60.     fprintf(stdout, "/////CORE INITIALIZATION STARTED/////\n");
  61.     //Initialize GLFW//
  62.     if (!glfwInit()) {
  63.         fprintf(stderr, "Failed to initialize GLFW\n");
  64.         system("PAUSE");
  65.         return -1;
  66.     } else
  67.         fprintf(stdout, "GLFW initialized successfully!\n");
  68.  
  69.     //FSAA because AWESOME//
  70.     //glfwWindowHint(GLFW_SAMPLES, 1);
  71.  
  72.     //Create GLFW window//
  73.     GLFWwindow* window;
  74.     window = glfwCreateWindow(1280, 720, "AuLC++Port", NULL, NULL);
  75.     if (!window) {
  76.         fprintf(stderr, "Failed to open GLFW window.\n");
  77.         glfwTerminate();
  78.         exit(EXIT_FAILURE);
  79.     } else
  80.         fprintf(stdout, "GLFW window created successfully!.\n");
  81.     glfwMakeContextCurrent(window);
  82.    
  83.     //Print Version//
  84.     printf("OpenGL Version: %s\n", glGetString(GL_VERSION));
  85.  
  86.     //Initialize GLEW after context creation//
  87.     if (glewInit() != GLEW_OK) {
  88.         fprintf(stderr, "Failed to initialize GLEW\n");
  89.         system("PAUSE");
  90.         return -1;
  91.     } else
  92.         fprintf(stdout, "GLEW initialized successfully!\n");
  93.     fprintf(stdout, "/////CORE INITIALIZATION COMPLETED/////\n\n");
  94.  
  95.     //Peach clear color//
  96.     glClearColor(1.0f, 0.6f, 0.3f, 1.0f);
  97.  
  98.     //Update Loop//
  99.     do {
  100.         //Clear color and depth//
  101.         glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  102.  
  103.         //This is bad outdated practice, don't do it lol//
  104.         float r = 1.0;
  105.         glBegin(GL_TRIANGLES);
  106.         glColor3f(1.0f, 0.0f, 0.0f);
  107.         glVertex2f(-0.5f*r, -0.7f*r);
  108.  
  109.         glColor3f(1.0f, 1.0f, 0.0f);
  110.         glVertex2f(0.1f*r, 0.7f*r);
  111.        
  112.         glColor3f(static_cast<float>(sin(tickNum / 100.0f)*1.0f), 1.0f, 1.0f);
  113.         glVertex2f(0.7f*r, 0.0f - 0.6f);
  114.         glEnd();
  115.        
  116.         //Swap buffers//
  117.         glfwSwapBuffers(window);
  118.  
  119.         //Poll events, this is like check if window closed, key pressed, etc.//
  120.         glfwPollEvents();
  121.  
  122.         //Increase tick//
  123.         tickNum++;
  124.  
  125.         //Refresh Resolution//
  126.         glfwGetWindowSize(window, &resSX, &resSY);
  127.         setProjections();
  128.     } while (!glfwWindowShouldClose(window));
  129.  
  130.     //Close window and end GLFW when finished//
  131.     glfwDestroyWindow(window);
  132.     glfwTerminate();
  133.  
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement