memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.17k stars 775 forks source link

VS2015CE and NanoVG how to prepare prject #367

Open DigitalPilgrim opened 7 years ago

DigitalPilgrim commented 7 years ago

Hello

I want try NanoVG as UI for my applications. I am new in OpenGL and have trouble with run NanoVG with GLFW.

here is my code

#include <glfw3.h>
#define NANOVG_GL2_IMPLEMENTATION
#include <nanovg.h>
#include <nanovg_gl.h>
NVGcontext* vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
void DrawNVG(NVGcontext* vg)
{
    nvgBeginPath(vg);
    nvgRect(vg, 100, 100, 120, 30);
    nvgFillColor(vg, nvgRGBA(255, 192, 0, 255));
    nvgFill(vg);
}
// ...
// sample code for glfw here
// ...

compiler fail and here is error list:

1>D:\path\to\nanovg\src\nanovg_gl.h(339): error C3861: 'glBlendFuncSeparate': identifier not found
1>D:\...\src\nanovg_gl.h(400): error C2065: 'GLchar': undeclared identifier
1>D:\...\src\nanovg_gl.h(400): error C2146: syntax error: missing ';' before identifier 'str'
1>D:\...\src\nanovg_gl.h(400): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(402): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(402): error C3861: 'glGetShaderInfoLog': identifier not found
1>D:\...\src\nanovg_gl.h(404): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(405): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(410): error C2065: 'GLchar': undeclared identifier
1>D:\...\src\nanovg_gl.h(410): error C2146: syntax error: missing ';' before identifier 'str'
1>D:\...\src\nanovg_gl.h(410): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(412): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(412): error C3861: 'glGetProgramInfoLog': identifier not found
1>D:\...\src\nanovg_gl.h(414): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(415): error C2065: 'str': undeclared identifier
1>D:\...\src\nanovg_gl.h(439): error C3861: 'glCreateProgram': identifier not found
1>D:\...\src\nanovg_gl.h(440): error C2065: 'GL_VERTEX_SHADER': undeclared identifier
1>D:\...\src\nanovg_gl.h(440): error C3861: 'glCreateShader': identifier not found
1>D:\...\src\nanovg_gl.h(441): error C2065: 'GL_FRAGMENT_SHADER': undeclared identifier
1>D:\...\src\nanovg_gl.h(441): error C3861: 'glCreateShader': identifier not found
1>D:\...\src\nanovg_gl.h(443): error C3861: 'glShaderSource': identifier not found
1>D:\...\src\nanovg_gl.h(445): error C3861: 'glShaderSource': identifier not found
1>D:\...\src\nanovg_gl.h(447): error C3861: 'glCompileShader': identifier not found
1>D:\...\src\nanovg_gl.h(448): error C2065: 'GL_COMPILE_STATUS': undeclared identifier
1>D:\...\src\nanovg_gl.h(448): error C3861: 'glGetShaderiv': identifier not found
1>D:\...\src\nanovg_gl.h(454): error C3861: 'glCompileShader': identifier not found
1>D:\...\src\nanovg_gl.h(455): error C2065: 'GL_COMPILE_STATUS': undeclared identifier
1>D:\...\src\nanovg_gl.h(455): error C3861: 'glGetShaderiv': identifier not found
1>D:\...\src\nanovg_gl.h(461): error C3861: 'glAttachShader': identifier not found
1>D:\...\src\nanovg_gl.h(462): error C3861: 'glAttachShader': identifier not found
1>D:\...\src\nanovg_gl.h(464): error C3861: 'glBindAttribLocation': identifier not found
1>D:\...\src\nanovg_gl.h(465): error C3861: 'glBindAttribLocation': identifier not found
1>D:\...\src\nanovg_gl.h(467): error C3861: 'glLinkProgram': identifier not found
1>D:\...\src\nanovg_gl.h(468): error C2065: 'GL_LINK_STATUS': undeclared identifier
1>D:\...\src\nanovg_gl.h(468): error C3861: 'glGetProgramiv': identifier not found
1>D:\...\src\nanovg_gl.h(484): error C3861: 'glDeleteProgram': identifier not found
1>D:\...\src\nanovg_gl.h(486): error C3861: 'glDeleteShader': identifier not found
1>D:\...\src\nanovg_gl.h(488): error C3861: 'glDeleteShader': identifier not found
1>D:\...\src\nanovg_gl.h(493): error C3861: 'glGetUniformLocation': identifier not found
1>D:\...\src\nanovg_gl.h(494): error C3861: 'glGetUniformLocation': identifier not found
1>D:\...\src\nanovg_gl.h(499): error C3861: 'glGetUniformLocation': identifier not found
1>D:\...\src\nanovg_gl.h(695): error C3861: 'glGenBuffers': identifier not found
1>D:\...\src\nanovg_gl.h(752): error C2065: 'GL_GENERATE_MIPMAP': undeclared identifier
1>D:\...\src\nanovg_gl.h(790): error C2065: 'GL_CLAMP_TO_EDGE': undeclared identifier
1>D:\...\src\nanovg_gl.h(795): error C2065: 'GL_CLAMP_TO_EDGE': undeclared identifier
1>D:\...\src\nanovg_gl.h(951): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
1>D:\...\src\nanovg_gl.h(975): error C3861: 'glUniform4fv': identifier not found
1>D:\...\src\nanovg_gl.h(1009): error C2065: 'GL_INCR_WRAP': undeclared identifier
1>D:\...\src\nanovg_gl.h(1009): error C3861: 'glStencilOpSeparate': identifier not found
1>D:\...\src\nanovg_gl.h(1010): error C2065: 'GL_DECR_WRAP': undeclared identifier
1>D:\...\src\nanovg_gl.h(1010): error C3861: 'glStencilOpSeparate': identifier not found
1>D:\...\src\nanovg_gl.h(1170): error C3861: 'glUseProgram': identifier not found
1>D:\...\src\nanovg_gl.h(1182): error C2065: 'GL_TEXTURE0': undeclared identifier
1>D:\...\src\nanovg_gl.h(1182): error C3861: 'glActiveTexture': identifier not found
1>D:\...\src\nanovg_gl.h(1206): error C2065: 'GL_ARRAY_BUFFER': undeclared identifier
1>D:\...\src\nanovg_gl.h(1206): error C3861: 'glBindBuffer': identifier not found
1>D:\...\src\nanovg_gl.h(1207): error C2065: 'GL_ARRAY_BUFFER': undeclared identifier
1>D:\...\src\nanovg_gl.h(1207): error C2065: 'GL_STREAM_DRAW': undeclared identifier
1>D:\...\src\nanovg_gl.h(1207): error C3861: 'glBufferData': identifier not found
1>D:\...\src\nanovg_gl.h(1208): error C3861: 'glEnableVertexAttribArray': identifier not found
1>D:\...\src\nanovg_gl.h(1209): error C3861: 'glEnableVertexAttribArray': identifier not found
1>D:\...\src\nanovg_gl.h(1210): error C3861: 'glVertexAttribPointer': identifier not found
1>D:\...\src\nanovg_gl.h(1211): error C3861: 'glVertexAttribPointer': identifier not found
1>D:\...\src\nanovg_gl.h(1214): error C3861: 'glUniform1i': identifier not found
1>D:\...\src\nanovg_gl.h(1215): error C3861: 'glUniform2fv': identifier not found
1>D:...\src\nanovg_gl.h(1234): error C3861: 'glDisableVertexAttribArray': identifier not found
1>D:\...\src\nanovg_gl.h(1235): error C3861: 'glDisableVertexAttribArray': identifier not found
1>D:\...\src\nanovg_gl.h(1240): error C2065: 'GL_ARRAY_BUFFER': undeclared identifier
1>D:\...\src\nanovg_gl.h(1240): error C3861: 'glBindBuffer': identifier not found
1>D:\...\src\nanovg_gl.h(1241): error C3861: 'glUseProgram': identifier not found
1>D:\...\src\nanovg_gl.h(1529): error C3861: 'glDeleteBuffers': identifier not found
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Glfw sample code (without nanovg included) compile without any issue. What is right set up for running nanovg?

memononen commented 7 years ago

I recommend to take a look at the GLFW tutorials first on how to set up an OpenGL window. Then it should be pretty straight forward to setup the NanoVG context.

Note, you cannot create it globally like in your example. You have to have OpenGL initialized first, just like in the examples.

DigitalPilgrim commented 7 years ago

I read this tutorial and run GLFW successful, problem is when I try only include nanovg with or without code:

#define NANOVG_GL2_IMPLEMENTATION
#include <nanovg.h>
#include <nanovg_gl.h>

btw. on main site is written only

#include <glfw3.h>
#define NANOVG_GL2_IMPLEMENTATION
#include <nanovg_gl.h>

without nanovg.h. If it isn't there, compiler get this error:

1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(59): error C2143: syntax error: missing ';' before '*'
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(60): error C2065: 'ctx': undeclared identifier
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(60): error C2182: 'nvgDeleteGL2': illegal use of type 'void'
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(62): error C2065: 'ctx': undeclared identifier
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(62): error C2275: 'GLuint': illegal use of this type as an expression
1>  C:\Program Files (x86)\Windows Kits\8.1\Include\um\GL/gl.h(57): note: see declaration of 'GLuint'
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(62): error C2146: syntax error: missing ')' before identifier 'textureId'
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(63): error C2065: 'ctx': undeclared identifier
1>D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(63): error C2062: type 'int' unexpected
1>d:\programi\development\nanovg\nanovg-master2\src\nanovg.h(33): error C2378: 'NVGcontext': redefinition; symbol cannot be overloaded with a typedef
1>  D:\Programi\Development\NanoVG\nanovg-master2\src\nanovg_gl.h(59): note: see declaration of 'NVGcontext'
// ... long list

and only nanovg.h only compiler errors:

1>Source.obj : error LNK2001: unresolved external symbol _nvgBeginPath
1>Source.obj : error LNK2001: unresolved external symbol _nvgFillColor
1>Source.obj : error LNK2001: unresolved external symbol _nvgFill
1>Source.obj : error LNK2001: unresolved external symbol _nvgRect
1>Source.obj : error LNK2001: unresolved external symbol _nvgRGBA
1>D:\...\GLFW test\Release\GLFW a NVG.exe : fatal error LNK1120: 5 unresolved externals
DigitalPilgrim commented 7 years ago

Ok, you are right. I have not properly installed opengl. I need glew with glfw to use NanoVG. Now, I am going to study opengl and NanoVG :)