diff --git a/CMakeLists.txt b/CMakeLists.txt index d83c02a0..0f4f093e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ if(X11_FOUND) list(APPEND ADDITIONAL_LIBRARIES "${X11_LIBRARIES}") # GLX - pkg_check_modules(GL QUIET gl xrender) + pkg_check_modules(GL QUIET glew xrender) if(GL_FOUND) add_definitions(-DGLX -DGL) list(APPEND INCLUDE_DIRS "${GL_INCLUDE_DIRS}") @@ -114,13 +114,19 @@ if(MSYS OR MINGW OR MSVC) if(GLU_LIB) find_library(DWM_LIB dwmapi) if(DWM_LIB) - add_definitions(-DWIN -DGL) - list(APPEND ADDITIONAL_SOURCES "src/output/graphical_win.c") - list(APPEND ADDITIONAL_SOURCES "src/input/wasapi.cpp") - list(APPEND ADDITIONAL_LIBRARIES "-lgdi32") - list(APPEND ADDITIONAL_LIBRARIES "-lopengl32") - list(APPEND ADDITIONAL_LIBRARIES "-lglu32") - list(APPEND ADDITIONAL_LIBRARIES "-ldwmapi") + find_library(GLEW_LIB glew32) + if(GLEW_LIB) + add_definitions(-DWIN -DGL) + list(APPEND ADDITIONAL_SOURCES "src/output/graphical_win.c") + list(APPEND ADDITIONAL_SOURCES "src/input/wasapi.cpp") + list(APPEND ADDITIONAL_LIBRARIES "-lgdi32") + list(APPEND ADDITIONAL_LIBRARIES "-lopengl32") + list(APPEND ADDITIONAL_LIBRARIES "-lglu32") + list(APPEND ADDITIONAL_LIBRARIES "-lglew32") + list(APPEND ADDITIONAL_LIBRARIES "-ldwmapi") + else() + message("GLEW library not found") + endif() else() message("DWMAPI library not found") endif() diff --git a/src/config.c b/src/config.c index c0718cdb..2db0c53f 100644 --- a/src/config.c +++ b/src/config.c @@ -14,6 +14,10 @@ #include #include +#ifdef WIN + #include +#endif + #include "output/graphical.h" #include "config.h" diff --git a/src/config.h b/src/config.h index 2db8868d..ac90ec0d 100644 --- a/src/config.h +++ b/src/config.h @@ -5,7 +5,7 @@ struct config_params { double monstercat, integral, gravity, ignore, sens, logScale, logBegin, logEnd, eqBalance, foreground_opacity, background_opacity; unsigned int lowcf, highcf, shdw, shdw_col, inputsize, fftsize, gradients, - bgcol, col; + bgcol, col, bars; double *smooth; int smcount, im, om, autobars, stereo, is_bin, ascii_range, vsync, bit_format, fixedbars, framerate, bw, bs, autosens, overshoot, waves, diff --git a/src/output/graphical.c b/src/output/graphical.c index 4c3578d6..c69cea6f 100644 --- a/src/output/graphical.c +++ b/src/output/graphical.c @@ -1,5 +1,7 @@ #include "graphical.h" #include "../config.h" +#include +#include #include #include @@ -37,84 +39,86 @@ void calculate_win_pos(int *winX, int *winY, int winW, int winH, int scrW, int s } #ifdef GL +unsigned int VBObuffer; +float glBars[1600]; // 2*4*200 + +static unsigned int CompileShader(unsigned int type, char *source) { + unsigned int id = glCreateShader(type); + glShaderSource(id, 1, &source, NULL); + glCompileShader(id); + + int result; + glGetShaderiv(id, GL_COMPILE_STATUS, &result); + if(result == GL_FALSE) { + int length; + glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length); + char *message = (char*)alloca(length*sizeof(char)); + glGetShaderInfoLog(id, length, &length, message); + fprintf(stderr, "Failed to compile %s shader: %s\n", type==GL_VERTEX_SHADER? "vertex" : "fragment", message); + + glDeleteShader(id); + return 0; + } + + return id; +} + +static unsigned int CreateShader(const char* vertexShader, + const char* fragmentShader) { + unsigned int program = glCreateProgram(); + unsigned int vs = CompileShader(GL_VERTEX_SHADER, vertexShader); + unsigned int fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader); + + glAttachShader(program, vs); + glAttachShader(program, fs); + glLinkProgram(program); + glValidateProgram(program); + + glDeleteShader(vs); + glDeleteShader(fs); + + return program; +} + +void VBOGLsetup() { + glewInit(); + + for(int i=0; i<200; i++) glBars[i] = 0.0; + glGenBuffers(1, &VBObuffer); + glBindBuffer(GL_ARRAY_BUFFER, VBObuffer); + glBufferData(GL_ARRAY_BUFFER, 1600*sizeof(float), glBars, GL_DYNAMIC_DRAW); + + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float)*2, 0); + + char *vertex = "void main(){ \n" + " gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" + "}\n"; + char *fragment = "void main(){\n" + " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);\n" + "}\n"; + + unsigned int shader = CreateShader(vertex, fragment); + glUseProgram(shader); +} + +void VBOGLdestroy() { + //free(glBars); +} + int drawGLBars(int rest, int bars, double colors[8], double gradColors[24], int *f) { for(int i = 0; i < bars; i++) { - double point[4]; - point[0] = rest+(p.bw+p.bs)*i; - point[1] = rest+(p.bw+p.bs)*i+p.bw; - point[2] = (unsigned int)f[i]+p.shdw> (unsigned int)p.h-p.shdw ? (unsigned int)p.h-p.shdw : (unsigned int)f[i]+p.shdw; - point[3] = p.shdw; - - glBegin(GL_QUADS); - if(p.shdw) { - // left side - glColor4d(colors[5], colors[6], colors[7], colors[4]); - glVertex2d(point[0], point[2]); - glVertex2d(point[0], point[3]); - glColor4d(0.0, 0.0, 0.0, 0.0); - glVertex2d(point[0]-p.shdw/2, point[3]-p.shdw); - glVertex2d(point[0]-p.shdw/2, point[2]+p.shdw/2); - - // right side - glColor4d(colors[5], colors[6], colors[7], colors[4]); - glVertex2d(point[1], point[2]); - glVertex2d(point[1], point[3]); - glColor4d(0.0, 0.0, 0.0, 0.0); - glVertex2d(point[1]+p.shdw, point[3]-p.shdw); - glVertex2d(point[1]+p.shdw, point[2]+p.shdw/2); - - // top side - glColor4d(colors[5], colors[6], colors[7], colors[4]); - glVertex2d(point[1], point[2]); - glVertex2d(point[0], point[2]); - glColor4d(0.0, 0.0, 0.0, 0.0); - glVertex2d(point[0]-p.shdw/2, point[2]+p.shdw/2); - glVertex2d(point[1]+p.shdw, point[2]+p.shdw/2); - - // bottom side - glColor4d(colors[5], colors[6], colors[7], colors[4]); - glVertex2d(point[1], point[3]); - glVertex2d(point[0], point[3]); - glColor4d(0.0, 0.0, 0.0, 0.0); - glVertex2d(point[0]-p.shdw/2, point[3]-p.shdw); - glVertex2d(point[1]+p.shdw, point[3]-p.shdw); - } - - if(p.gradients) { - double progress = (double)(point[2]-p.shdw)/(double)((unsigned int)p.h-p.shdw); - int gcMax = ceil((p.gradients-1.0)*progress); - double cutLenght = ((unsigned int)p.h-p.shdw)/(double)(p.gradients-1.0); - for(int gcPhase=0; gcPhase (unsigned int)p.h-p.shdw ? (unsigned int)p.h-p.shdw : (unsigned int)f[i]+p.shdw; + glBars[i*8+3] = glBars[i*8+1]; + glBars[i*8+5] = p.shdw; + glBars[i*8+7] = glBars[i*8+5]; } + glBufferSubData(GL_ARRAY_BUFFER, 0, 8*bars*sizeof(float), glBars); + glDrawArrays(GL_QUADS, 0, 4*bars); return 0; } #endif diff --git a/src/output/graphical.h b/src/output/graphical.h index aa16f17c..9b01dada 100644 --- a/src/output/graphical.h +++ b/src/output/graphical.h @@ -1,6 +1,11 @@ #ifndef H_GRAPHICAL #define H_GRAPHICAL +#ifdef GL + #include + int drawGLBars(int rest, int bars, double colors[8], double gradColors[24], int *f); +#endif + #ifdef GLX #include GLXContext xavaGLXContext; @@ -8,13 +13,10 @@ extern int GLXmode; #endif -#ifdef GL - #include - int drawGLBars(int rest, int bars, double colors[8], double gradColors[24], int *f); -#endif - void calculate_win_pos(int *winX, int *winY, int winW, int winH, int scrW, int scrH, char *winPos); +void VBOGLsetup(); + static const unsigned int definedColors[] = {0x000000, 0xFF0000, 0x00FF00, 0xFFFF00, 0x0000FF, 0xFF00FF, 0x00FFFF, 0xFFFFFF}; #define ARGB_A_32(x) ((x>>24)&0xff) diff --git a/src/output/graphical_win.c b/src/output/graphical_win.c index 95f8d5dd..0f112bd9 100644 --- a/src/output/graphical_win.c +++ b/src/output/graphical_win.c @@ -366,6 +366,7 @@ int init_window_win() { void apply_win_settings() { clear_screen_win(); resize_framebuffer(p.w, p.h); + VBOGLsetup(); //ReleaseDC(xavaWinWindow, xavaWinFrame); PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); @@ -404,15 +405,15 @@ void draw_graphical_win(int bars, int rest, int f[200]) { if(drawGLBars(rest, bars, glColors, gradColors, f)) exit(EXIT_FAILURE); // dumb workarounds for dumb OSes - glBegin(GL_QUADS); - glColor4d(ARGB_R_32(p.bgcol)/255.0, ARGB_G_32(p.bgcol)/255.0, ARGB_B_32(p.bgcol)/255.0, p.background_opacity); - glVertex2d(0.0, 0.0); - glVertex2d(0.0, p.h); - glVertex2d(p.w, p.h); - glVertex2d(p.w, 0.0); - glEnd(); - - glFlush(); + //glBegin(GL_QUADS); + // glColor4d(ARGB_R_32(p.bgcol)/255.0, ARGB_G_32(p.bgcol)/255.0, ARGB_B_32(p.bgcol)/255.0, p.background_opacity); + // glVertex2d(0.0, 0.0); + // glVertex2d(0.0, p.h); + // glVertex2d(p.w, p.h); + // glVertex2d(p.w, 0.0); + //glEnd(); + + //glFlush(); // swap buffers SwapBuffers(xavaWinFrame); diff --git a/src/output/graphical_win.h b/src/output/graphical_win.h index 4df289e0..bc8efe77 100644 --- a/src/output/graphical_win.h +++ b/src/output/graphical_win.h @@ -1,8 +1,6 @@ #include #include -#include -#include -#define WGL_WGLEXT_PROTOTYPES +#include #include #include #include diff --git a/src/output/graphical_x.c b/src/output/graphical_x.c index d9b2376c..ecc327e3 100644 --- a/src/output/graphical_x.c +++ b/src/output/graphical_x.c @@ -371,13 +371,14 @@ int apply_window_settings_x() glViewport(0, 0, p.w, p.h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - + glOrtho(0, (double)p.w, 0, (double)p.h, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Vsync causes problems on NVIDIA GPUs, looking for possible workarounds/fixes glXSwapIntervalEXT(xavaXDisplay, xavaXWindow, p.vsync); + VBOGLsetup(); #endif } else clear_screen_x(); @@ -486,7 +487,7 @@ void draw_graphical_x(int bars, int rest, int f[200], int flastd[200]) if(GLXmode) { #ifdef GLX - for(int i=0; i p.w) p.autobars = 1; } - //getting orignial numbers of barss incase of resize + //getting orignial numbers of bars incase of resize if (p.autobars == 1) { bars = (p.w + p.bs) / (p.bw + p.bs);