Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.49 KB | None | 0 0
  1. //--------------------------------------------------------------------------------------
  2. // BTH - Stefan Petersson 2014.
  3. // - updated by FLL
  4. //--------------------------------------------------------------------------------------
  5. #include <windows.h>
  6.  
  7. #include <string>
  8. #include <fstream>
  9. #include <streambuf>
  10.  
  11. #define GLM_ENABLE_EXPERIMENTAL
  12. #include "imgui/imgui.h"
  13. #include "imgui/imgui_impl_win32.h"
  14. #include "imgui/imgui_impl_opengl3.h"
  15. #include "glm/glm.hpp"
  16. #include "glm/ext.hpp"
  17. #include "glm/gtc/matrix_transform.hpp"
  18. #include "glm/gtx/transform.hpp"
  19. #include <gl/glew.h>
  20. #include <gl/GL.h>
  21. #define STB_IMAGE_IMPLEMENTATION
  22. #include "bth_image.h"
  23.  
  24. #pragma comment(lib, "opengl32.lib")
  25. #pragma comment(lib, "glew32.lib")
  26.  
  27. #define WIDTH 1024
  28. #define HEIGHT 768
  29.  
  30. using namespace std;
  31. HWND InitWindow(HINSTANCE hInstance);
  32. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  33. HGLRC CreateOpenGLContext(HWND wndHandle);
  34.  
  35. // OpenGL uses unsigned integers to keep track of
  36. // created resources (shaders, vertices, textures, etc)
  37. // For simplicity, we make them global here, but it is
  38. // safe to put them in a class and pass around...
  39. GLuint gVertexBuffer = 0;
  40. GLuint gVertexAttribute = 0;
  41. GLuint gShaderProgram = 0;
  42. GLuint bth_tex;
  43. float gFloat = 0;
  44. float gClearColour[3] {};
  45.  
  46. float gUniformColour[3] {};
  47. GLint gUniformColourLoc = -1;
  48.  
  49. float gOffsetX = 0.0f;
  50. float gIncrement = 0.0f;
  51. //const unsigned int BTH_IMAGE_WIDTH = 64;
  52. //const unsigned int BTH_IMAGE_HEIGHT = 64;
  53.  
  54. //unsigned char BTH_IMAGE_DATA[] = { 0 };
  55.  
  56. glm::mat4 WorldMatrix;
  57. glm::mat4 ViewMatrix;
  58. glm::mat4 ProjectionMatrix;
  59.  
  60. // macro that returns "char*" with offset "i"
  61. // BUFFER_OFFSET(5) transforms in "(char*)nullptr+(5)"
  62. #define BUFFER_OFFSET(i) ((char *)nullptr + (i))
  63.  
  64. void CreateTexture() {
  65. glGenTextures(1, &bth_tex);
  66. glActiveTexture(GL_TEXTURE0);
  67. glBindTexture(GL_TEXTURE_2D, bth_tex);
  68. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  69. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  70. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  71. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  72.  
  73. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_RGBA,GL_UNSIGNED_BYTE, BTH_IMAGE_DATA);
  74.  
  75. }
  76.  
  77.  
  78. void createMatrix(float time) {
  79. glm::mat4 scaleMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 1.0f));
  80.  
  81. //glm::mat4 rotationMatrix = glm::rotate(glm::mat4(1.0f), 3.14f, glm::vec3(1.0));
  82. glm::mat4 rotationMatrix = glm::rotate(scaleMatrix, 0.05f * time, glm::vec3(0, 1, 0));
  83.  
  84.  
  85. WorldMatrix = scaleMatrix * rotationMatrix;
  86.  
  87.  
  88. ProjectionMatrix = glm::perspective(
  89. glm::radians(3.14f*0.45f), // The vertical Field of View, in radians: the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in)
  90. (float)WIDTH / (float)HEIGHT, // Aspect Ratio. Depends on the size§ of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ?
  91. 0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues.
  92. 20.0f // Far clipping plane. Keep as little as possible.
  93. );
  94. glm::mat4 Projection = glm::perspective(3.14f * 0.45f, (float)WIDTH / (float)HEIGHT, 0.1f, 20.0f);
  95. glm::mat4 View = glm::lookAt(
  96. glm::vec3(0, 0, -2), // Camera is at (4,3,3), in World Space
  97. glm::vec3(0, 0, 0), // and looks at the origin
  98. glm::vec3(0, 1, 0) // Head is up (set to 0,-1,0 to look upside-down)
  99. );
  100.  
  101. WorldMatrix = Projection * View * WorldMatrix; // projectionMatrix * ViewMatrix * worldMatrix;
  102. }
  103. void CreateShaders()
  104. {
  105. // local buffer to store error strings when compiling.
  106. char buff[1024];
  107. memset(buff, 0, 1024);
  108. GLint compileResult = 0;
  109.  
  110. //create vertex shader "name" and store it in "vs"
  111. GLuint vs = glCreateShader(GL_VERTEX_SHADER);
  112.  
  113. // open .glsl file and put it in a string
  114. ifstream shaderFile("VertexShader.glsl");
  115. std::string shaderText((std::istreambuf_iterator<char>(shaderFile)), std::istreambuf_iterator<char>());
  116. shaderFile.close();
  117.  
  118. // glShaderSource requires a double pointer.
  119. // get the pointer to the c style string stored in the string object.
  120. const char* shaderTextPtr = shaderText.c_str();
  121.  
  122. // ask GL to use this string a shader code source
  123. glShaderSource(vs, 1, &shaderTextPtr, nullptr);
  124.  
  125. // try to compile this shader source.
  126. glCompileShader(vs);
  127.  
  128. // check for compilation error
  129. glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
  130. if (compileResult == GL_FALSE) {
  131. // query information about the compilation (nothing if compilation went fine!)
  132. glGetShaderInfoLog(vs, 1024, nullptr, buff);
  133. // print to Visual Studio debug console output
  134. OutputDebugStringA(buff);
  135. }
  136.  
  137. // repeat process for Fragment Shader (or Pixel Shader)
  138. GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
  139. shaderFile.open("Fragment.glsl");
  140. shaderText.assign((std::istreambuf_iterator<char>(shaderFile)), std::istreambuf_iterator<char>());
  141. shaderFile.close();
  142. shaderTextPtr = shaderText.c_str();
  143. glShaderSource(fs, 1, &shaderTextPtr, nullptr);
  144. glCompileShader(fs);
  145. // query information about the compilation (nothing if compilation went fine!)
  146. compileResult = GL_FALSE;
  147. glGetShaderiv(fs, GL_COMPILE_STATUS, &compileResult);
  148. if (compileResult == GL_FALSE) {
  149. // query information about the compilation (nothing if compilation went fine!)
  150. memset(buff, 0, 1024);
  151. glGetShaderInfoLog(fs, 1024, nullptr, buff);
  152. // print to Visual Studio debug console output
  153. OutputDebugStringA(buff);
  154. }
  155.  
  156. //link shader program (connect vs and ps)
  157. gShaderProgram = glCreateProgram();
  158. glAttachShader(gShaderProgram, fs);
  159. glAttachShader(gShaderProgram, vs);
  160. glLinkProgram(gShaderProgram);
  161.  
  162. // check once more, if the Vertex Shader and the Fragment Shader can be used
  163. // together
  164. compileResult = GL_FALSE;
  165. glGetProgramiv(gShaderProgram, GL_LINK_STATUS, &compileResult);
  166. if (compileResult == GL_FALSE) {
  167. // query information about the compilation (nothing if compilation went fine!)
  168. memset(buff, 0, 1024);
  169. glGetProgramInfoLog(gShaderProgram, 1024, nullptr, buff);
  170. // print to Visual Studio debug console output
  171. OutputDebugStringA(buff);
  172. }
  173. // in any case (compile sucess or not), we only want to keep the
  174. // Program around, not the shaders.
  175. glDetachShader(gShaderProgram, vs);
  176. glDetachShader(gShaderProgram, fs);
  177. glDeleteShader(vs);
  178. glDeleteShader(fs);
  179. }
  180.  
  181. void CreateTriangleData()
  182. {
  183. // this is how we will structure the input data for the vertex shader
  184. // every six floats, is one vertex.
  185. struct TriangleVertex
  186. {
  187. float x, y, z;
  188. float r, g, b;
  189. float myAttr;
  190. };
  191.  
  192. // create the actual data in plane Z = 0
  193. // This is called an Array of Structs (AoS) because we will
  194. // end up with an array of many of these structs.
  195. TriangleVertex triangleVertices[6] =
  196. {
  197. // pos and color for each vertex
  198. { -0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f },
  199. { -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f },
  200. { 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f },
  201. { -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f },
  202. { 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f },
  203. { 0.5f, -0.5f, 0.0f, 1.0f, 1.0f, 0.0f }
  204. };
  205.  
  206. // Vertex Array Object (VAO), description of the inputs to the GPU
  207. glGenVertexArrays(1, &gVertexAttribute);
  208. // bind is like "enabling" the object to use it
  209. glBindVertexArray(gVertexAttribute);
  210. // this activates the first and second attributes of this VAO
  211. // think of "attributes" as inputs to the Vertex Shader
  212. glEnableVertexAttribArray(0);
  213. glEnableVertexAttribArray(1);
  214. glEnableVertexAttribArray(2);
  215.  
  216. // create a vertex buffer object (VBO) id (out Array of Structs on the GPU side)
  217. glGenBuffers(1, &gVertexBuffer);
  218.  
  219. // Bind the buffer ID as an ARRAY_BUFFER
  220. glBindBuffer(GL_ARRAY_BUFFER, gVertexBuffer);
  221.  
  222. // This "could" imply copying to the GPU, depending on what the driver wants to do, and
  223. // the last argument (read the docs!)
  224. glBufferData(GL_ARRAY_BUFFER, sizeof(triangleVertices), triangleVertices, GL_STATIC_DRAW);
  225.  
  226. // query which "slot" corresponds to the input vertex_position in the Vertex Shader
  227. GLint vertexPos = glGetAttribLocation(gShaderProgram, "vertex_position");
  228. // if this returns -1, it means there is a problem, and the program will likely crash.
  229. // examples: the name is different or missing in the shader
  230.  
  231. if (vertexPos == -1) {
  232. OutputDebugStringA("Error, cannot find 'vertex_position' attribute in Vertex shader\n");
  233. return;
  234. }
  235.  
  236. // tell OpenGL about layout in memory (input assembler information)
  237. glVertexAttribPointer(
  238. vertexPos, // location in shader
  239. 3, // how many elements of type (see next argument)
  240. GL_FLOAT, // type of each element
  241. GL_FALSE, // integers will be normalized to [-1,1] or [0,1] when read...
  242. sizeof(TriangleVertex), // distance between two vertices in memory (stride)
  243. BUFFER_OFFSET(0) // offset of FIRST vertex in the list.
  244. );
  245.  
  246. // repeat the process for the second attribute.
  247. // query which "slot" corresponds to the input vertex_color in the Vertex Shader
  248. GLuint vertexColor = glGetAttribLocation(gShaderProgram, "vertex_color");
  249. glVertexAttribPointer(
  250. vertexColor,
  251. 3,
  252. GL_FLOAT,
  253. GL_FALSE, sizeof(TriangleVertex), // distance between two vertexColor
  254. BUFFER_OFFSET(sizeof(float)*3) // note, the first color starts after the first vertex.
  255. );
  256.  
  257. GLint myAttrLoc = glGetAttribLocation(gShaderProgram, "myAttr");
  258. glVertexAttribPointer(myAttrLoc, 1, GL_FLOAT, GL_FALSE, sizeof(TriangleVertex), BUFFER_OFFSET(sizeof(float)*6));
  259. }
  260.  
  261. void SetViewport()
  262. {
  263. // usually (not necessarily) this matches with the window size
  264. glViewport(0, 0, WIDTH, HEIGHT);
  265. }
  266.  
  267. void Render()
  268. {
  269. glClearColor(0, 0, 0, 1);
  270. glClear(GL_COLOR_BUFFER_BIT);
  271. glUseProgram(gShaderProgram);
  272. glActiveTexture(GL_TEXTURE0);
  273. glBindTexture(GL_TEXTURE_2D, bth_tex);
  274. glBindVertexArray(gVertexAttribute);
  275. glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  276. // set the color TO BE used (this does not clear the screen right away)
  277. glClearColor(gClearColour[0], gClearColour[1],gClearColour[2],1.0);
  278.  
  279. // use the color to clear the color buffer (clear the color buffer only)
  280. glClear(GL_COLOR_BUFFER_BIT);
  281.  
  282. // tell opengl we want to use the gShaderProgram
  283. glUseProgram(gShaderProgram);
  284.  
  285. glUniform3fv(gUniformColourLoc, 1, &gUniformColour[0]);
  286.  
  287. GLuint MatrixIDWorld = glGetUniformLocation(gShaderProgram, "WorldMatrix");
  288. glUniformMatrix4fv(MatrixIDWorld, 1, GL_FALSE, glm::value_ptr(WorldMatrix));
  289. GLuint MatrixIDView = glGetUniformLocation(gShaderProgram, "ViewMatrix");
  290. glUniformMatrix4fv(MatrixIDView, 1, GL_FALSE, glm::value_ptr(ViewMatrix));
  291. GLuint MatrixIDProjection = glGetUniformLocation(gShaderProgram, "ProjectionMatrix");
  292. glUniformMatrix4fv(MatrixIDProjection, 1, GL_FALSE, glm::value_ptr(ProjectionMatrix));
  293.  
  294. // tell opengl we are going to use the VAO we described earlier
  295. glBindVertexArray(gVertexAttribute);
  296.  
  297. // ask OpenGL to draw 3 vertices starting from index 0 in the vertex array
  298. // currently bound (VAO), with current in-use shader. Use TOPOLOGY GL_TRIANGLES,
  299. // so for one triangle we need 3 vertices!
  300. glDrawArrays(GL_TRIANGLES, 0, 6);
  301. }
  302.  
  303. int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
  304. {
  305. MSG msg = { 0 };
  306. HWND wndHandle = InitWindow(hInstance); // 1. Skapa fönster
  307.  
  308. if (wndHandle)
  309. {
  310. HDC hDC = GetDC(wndHandle);
  311. HGLRC hRC = CreateOpenGLContext(wndHandle); //2. Skapa och koppla OpenGL context
  312.  
  313. glewInit(); //3. Initiera The OpenGL Extension Wrangler Library (GLEW)
  314.  
  315. IMGUI_CHECKVERSION();
  316. ImGui::CreateContext();
  317. ImGuiIO& io = ImGui::GetIO(); (void)io;
  318. ImGui_ImplWin32_Init(wndHandle);
  319. ImGui_ImplOpenGL3_Init();
  320. ImGui::StyleColorsDark();
  321.  
  322. // which OpenGL did we get?
  323. GLint glMajor, glMinor;
  324. glGetIntegerv(GL_MAJOR_VERSION, &glMajor);
  325. glGetIntegerv(GL_MAJOR_VERSION, &glMinor);
  326.  
  327. char buff[256] = {};
  328. sprintf_s(buff, 256, "OpenGL context version %d.%d created\n", glMajor, glMinor);
  329. OutputDebugStringA(buff);
  330.  
  331. SetViewport(); //4. Sätt viewport
  332.  
  333. CreateShaders(); //5. Skapa vertex- och fragment-shaders
  334.  
  335. CreateTriangleData(); //6. Definiera triangelvertiser, 7. Skapa vertex buffer object (VBO), 8.Skapa vertex array object (VAO)
  336.  
  337.  
  338. int width, height, nrChannels;
  339.  
  340. ShowWindow(wndHandle, nCmdShow);
  341.  
  342. gUniformColourLoc = glGetUniformLocation(gShaderProgram, "colourFromImGui");
  343. while (WM_QUIT != msg.message)
  344. {
  345. if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
  346. {
  347. TranslateMessage(&msg);
  348. DispatchMessage(&msg);
  349. }
  350. else
  351. {
  352. // move along X
  353. gIncrement += 1.0f * ImGui::GetIO().DeltaTime;
  354. if( gIncrement > 360){
  355. gIncrement == 0;
  356. }
  357. createMatrix(gIncrement); // 4.5 Skapar matriser (own)
  358.  
  359.  
  360. // prepare IMGUI output
  361. ImGui_ImplOpenGL3_NewFrame();
  362. ImGui_ImplWin32_NewFrame();
  363. ImGui::NewFrame();
  364. ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
  365. ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
  366. ImGui::SliderFloat("float", &gFloat, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
  367. ImGui::ColorEdit3("clear color", gClearColour); // Edit 3 floats representing a color
  368. ImGui::ColorEdit3("triangle color", gUniformColour);
  369. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  370. ImGui::End();
  371.  
  372. Render(); //9. Rendera
  373.  
  374. // actually render IMGUI interface
  375. ImGui::Render();
  376. ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
  377.  
  378.  
  379. SwapBuffers(hDC); //10. Växla front- och back-buffer
  380. }
  381. }
  382.  
  383. ImGui_ImplOpenGL3_Shutdown();
  384. ImGui_ImplWin32_Shutdown();
  385. ImGui::DestroyContext();
  386.  
  387. // release OpenGL context
  388. wglMakeCurrent(NULL, NULL);
  389. // release device context handle
  390. ReleaseDC(wndHandle, hDC);
  391. // delete context
  392. wglDeleteContext(hRC);
  393. // kill window
  394. DestroyWindow(wndHandle);
  395. }
  396.  
  397. return (int) msg.wParam;
  398. }
  399.  
  400. // Win32 specific code. Create a window with certain characteristics
  401. HWND InitWindow(HINSTANCE hInstance)
  402. {
  403. WNDCLASSEX wcex = { 0 };
  404. wcex.cbSize = sizeof(WNDCLASSEX);
  405. wcex.style = CS_HREDRAW | CS_VREDRAW;
  406. wcex.lpfnWndProc = WndProc;
  407. wcex.hInstance = hInstance;
  408. wcex.lpszClassName = L"BTH_GL_DEMO";
  409. if( !RegisterClassEx(&wcex) )
  410. return false;
  411.  
  412. // window size
  413. RECT rc = { 0, 0, WIDTH, HEIGHT };
  414. AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
  415.  
  416. // win32 call to create a window
  417. HWND handle = CreateWindow(
  418. L"BTH_GL_DEMO",
  419. L"BTH OpenGL Demo",
  420. WS_OVERLAPPEDWINDOW,
  421. CW_USEDEFAULT,
  422. CW_USEDEFAULT,
  423. rc.right - rc.left,
  424. rc.bottom - rc.top,
  425. nullptr,
  426. nullptr,
  427. hInstance,
  428. nullptr);
  429. return handle;
  430. }
  431.  
  432. extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  433. LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
  434. {
  435. if (ImGui_ImplWin32_WndProcHandler(hWnd, message, wParam, lParam))
  436. return true;
  437.  
  438. switch (message)
  439. {
  440. case WM_DESTROY:
  441. PostQuitMessage(0);
  442. break;
  443. }
  444.  
  445. return DefWindowProc(hWnd, message, wParam, lParam);
  446. }
  447.  
  448. HGLRC CreateOpenGLContext(HWND wndHandle)
  449. {
  450. //get handle to a device context (DC) for the client area
  451. //of a specified window or for the entire screen
  452. HDC hDC = GetDC(wndHandle);
  453.  
  454. //details: http://msdn.microsoft.com/en-us/library/windows/desktop/dd318286(v=vs.85).aspx
  455. static PIXELFORMATDESCRIPTOR pixelFormatDesc =
  456. {
  457. sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
  458. 1, // version number
  459. PFD_DRAW_TO_WINDOW | // support window
  460. PFD_SUPPORT_OPENGL | // support OpenGL
  461. PFD_DOUBLEBUFFER | // double buffered
  462. PFD_DEPTH_DONTCARE, // disable depth buffer <-- added by Stefan
  463. PFD_TYPE_RGBA, // RGBA type
  464. 32, // 32-bit color depth (4*8)
  465. 0, 0, 0, 0, 0, 0, // color bits ignored
  466. 0, // no alpha buffer
  467. 0, // shift bit ignored
  468. 0, // no accumulation buffer
  469. 0, 0, 0, 0, // accum bits ignored
  470. 0, // 24 // 0-bits for depth buffer <-- modified by Stefan
  471. 0, // 8 // no stencil buffer
  472. 0, // no auxiliary buffer
  473. PFD_MAIN_PLANE, // main layer
  474. 0, // reserved
  475. 0, 0, 0 // layer masks ignored
  476. };
  477.  
  478. //attempt to match an appropriate pixel format supported by a
  479. //device context to a given pixel format specification.
  480. int pixelFormat = ChoosePixelFormat(hDC, &pixelFormatDesc);
  481.  
  482. //set the pixel format of the specified device context
  483. //to the format specified by the iPixelFormat index.
  484. SetPixelFormat(hDC, pixelFormat, &pixelFormatDesc);
  485.  
  486. //create a new OpenGL rendering context, which is suitable for drawing
  487. //on the device referenced by hdc. The rendering context has the same
  488. //pixel format as the device context.
  489. HGLRC hRC = wglCreateContext(hDC);
  490.  
  491. //makes a specified OpenGL rendering context the calling thread's current
  492. //rendering context. All subsequent OpenGL calls made by the thread are
  493. //drawn on the device identified by hdc.
  494. wglMakeCurrent(hDC, hRC);
  495.  
  496. return hRC;
  497. }
  498.  
  499.  
  500.  
  501. #version 440
  502. layout(location = 0) in vec3 vertex_position;
  503. layout(location = 1) in vec3 vertex_tex;
  504. layout(location = 2) in float myAttr;
  505. layout(location = 0) out vec2 texOut;
  506.  
  507. layout(location=3) out float myAttrOut;
  508.  
  509.  
  510. uniform mat4 WorldMatrix;
  511. uniform mat4 ViewMatrix;
  512. uniform mat4 ProjectionMatrix;
  513.  
  514.  
  515. void main() {
  516. texOut = vertex_tex;
  517. myAttrOut = myAttr;
  518. gl_Position = WorldMatrix * vec4(vec3(vertex_position.x,vertex_position.yz), 1.0);
  519.  
  520. }
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533. #version 440
  534. // these values are interpolated at the rasteriser
  535. layout(location = 0) in vec2 texIn;
  536. uniform sampler2D texSampler;
  537. layout(location=3) in float myAttrOut;
  538.  
  539. // this is the final pixel colour
  540. out vec4 fragment_color;
  541.  
  542. // this is a uniform value, the very same value for ALL pixel shader executions
  543. layout(location = 5) uniform vec3 colourFromImGui;
  544.  
  545. void main () {
  546. vec4 mySample = texture(texSampler, vec2(texIn.S,1-texIn.t //vec4 (color, 1.0);
  547. fragment_color = mySample.rgb;
  548. //fragment_color = myAttrOut * vec4 (color * colourFromImGui, 1.0);
  549. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement