Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
C-Fu
OpenGL
Commits
9d35634c
Commit
9d35634c
authored
Nov 01, 2016
by
Anakin
Browse files
pass data (xyz, uv) with 1 buffer to shader,
bugs: 2 triangles are not painted, one is wrong positioned
parent
a875820f
Changes
3
Hide whitespace changes
Inline
Side-by-side
MshViewer/Header/OpenGLController.h
View file @
9d35634c
...
...
@@ -6,6 +6,23 @@
#include
<vector>
#include
"Object.h"
#define VERTEX_INDEX_XYZ 0
#define VERTEX_INDEX_UV 1
#define VERTEX_COMPONENTS_XYZ 3
#define VERTEX_COMPONENTS_UV 4
#define VERTEX_SIZE_XYZ (sizeof(float) * VERTEX_COMPONENTS_XYZ)
#define VERTEX_SIZE_UV (sizeof(float) * VERTEX_COMPONENTS_UV)
#define VERTEX_OFFSET_XYZ 0
#define VERTEX_OFFSET_UV (VERTEX_SIZE_XYZ)
struct
Vertex
{
GLfloat
position
[
3
];
GLfloat
uv
[
2
];
};
class
OpenGLController
{
////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -35,10 +52,10 @@ private:
// IDs ==========================
//object data
GLuint
gluiVertexArrayID
;
GLuint
gluiInstanceBufferID
;
GLuint
gluiVertexBufferID
;
//obj color
GLuint
gluiUVBufferID
;
GLuint
gluiTextureID
;
GLuint
gluiShaderPrgmID
;
GLuint
gluiSamplerID
;
...
...
MshViewer/Shader/VertexTextureShader.mv2shdr
View file @
9d35634c
...
...
@@ -3,6 +3,7 @@
// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
//layout(location = 2) in mat4 mvp;
// Output
out vec2 UV;
...
...
MshViewer/Source/OpenGlController.cpp
View file @
9d35634c
...
...
@@ -7,12 +7,11 @@
#include
<glm\gtc\matrix_transform.hpp>
#include
"shader.hpp"
#include
"Texture.h"
#include
<iostream>
#define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr"
#define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr"
//#define TEXTURE_NAME "Textures/texture32R.tga"
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
...
...
@@ -25,7 +24,7 @@ OpenGLController* OpenGLController::getInstance(int oglMajor, int oglMinor)
OpenGLController
::~
OpenGLController
()
{
glDeleteBuffers
(
1
,
&
glui
UV
BufferID
);
glDeleteBuffers
(
1
,
&
glui
Instance
BufferID
);
glDeleteBuffers
(
1
,
&
gluiVertexBufferID
);
glDeleteVertexArrays
(
1
,
&
gluiVertexArrayID
);
glDeleteProgram
(
gluiShaderPrgmID
);
...
...
@@ -72,7 +71,7 @@ void OpenGLController::initDefault()
iAntiAliasingLevel
=
4
;
glui
UV
BufferID
=
0
;
glui
Instance
BufferID
=
0
;
gluiTextureID
=
0
;
gluiShaderPrgmID
=
0
;
gluiSamplerID
=
0
;
...
...
@@ -113,7 +112,16 @@ void OpenGLController::processInit()
glBindVertexArray
(
gluiVertexArrayID
);
glGenBuffers
(
1
,
&
gluiVertexBufferID
);
glGenBuffers
(
1
,
&
gluiUVBufferID
);
glGenBuffers
(
1
,
&
gluiInstanceBufferID
);
// open attribute position
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiVertexBufferID
);
glVertexAttribPointer
(
VERTEX_INDEX_XYZ
,
VERTEX_COMPONENTS_XYZ
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
void
*
)
VERTEX_OFFSET_XYZ
);
glVertexAttribPointer
(
VERTEX_INDEX_UV
,
VERTEX_COMPONENTS_UV
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
void
*
)
VERTEX_OFFSET_UV
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
glEnableVertexAttribArray
(
0
);
glEnableVertexAttribArray
(
1
);
// get the painter ready
try
...
...
@@ -274,24 +282,9 @@ void OpenGLController::updateScene()
// tell sampler to use texture unit 0
glUniform1i
(
gluiSamplerID
,
0
);
// open attribute position
glEnableVertexAttribArray
(
0
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiVertexBufferID
);
glVertexAttribPointer
(
0
,
3
,
GL_FLOAT
,
GL_FALSE
,
0
,
0
);
// open attribute uv
glEnableVertexAttribArray
(
1
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiUVBufferID
);
glVertexAttribPointer
(
1
,
2
,
GL_FLOAT
,
GL_FALSE
,
0
,
0
);
//draw objects
//// TODO: for all
glDrawArrays
(
GL_TRIANGLES
,
0
,
vModels
.
front
()
->
meshSize
);
//close attributes
glDisableVertexAttribArray
(
0
);
glDisableVertexAttribArray
(
1
);
glfwSwapBuffers
(
pWindow
);
glfwPollEvents
();
...
...
@@ -357,48 +350,35 @@ void OpenGLController::loadMsh(const char * path)
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR_MIPMAP_LINEAR
);
glGenerateMipmap
(
GL_TEXTURE_2D
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiVertexBufferID
);
////TODO: for all
std
::
vector
<
GLfloat
>
tempVertex
;
std
::
vector
<
Vertex
>
tempBufferData
;
for
(
unsigned
int
i
=
0
;
i
<
vModels
.
front
()
->
meshSize
;
i
++
)
{
tempVertex
.
push_back
((
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
]);
tempVertex
.
push_back
((
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
+
1
]);
tempVertex
.
push_back
((
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
+
2
]);
}
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
tempVertex
)
*
tempVertex
.
size
(),
tempVertex
.
data
(),
GL_STATIC_DRAW
);
////TODO: for all
std
::
vector
<
GLfloat
>
tempUV
;
Vertex
tempVertex
;
tempVertex
.
position
[
0
]
=
(
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
];
tempVertex
.
position
[
1
]
=
(
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
+
1
];
tempVertex
.
position
[
2
]
=
(
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
+
2
];
if
(
vModels
.
front
()
->
uv
==
NULL
)
{
for
(
unsigned
int
i
=
0
;
i
<
vModels
.
front
()
->
meshSize
;
i
++
)
tempUV
.
push_back
(
1.0
);
}
else
{
for
(
unsigned
int
i
=
0
;
i
<
vModels
.
front
()
->
meshSize
;
i
++
)
if
(
vModels
.
front
()
->
uv
==
NULL
)
{
tempVertex
.
uv
[
0
]
=
1.0
;
tempVertex
.
uv
[
1
]
=
1.0
;
}
else
{
temp
UV
.
push_back
(
(
GLfloat
)
vModels
.
front
()
->
uv
[
vModels
.
front
()
->
mesh
[
i
]
*
2
]
)
;
temp
UV
.
push_back
(
(
GLfloat
)
vModels
.
front
()
->
uv
[
vModels
.
front
()
->
mesh
[
i
]
*
2
+
1
]
)
;
temp
Vertex
.
uv
[
0
]
=
(
GLfloat
)
vModels
.
front
()
->
uv
[
vModels
.
front
()
->
mesh
[
i
]
*
2
];
temp
Vertex
.
uv
[
1
]
=
(
GLfloat
)
vModels
.
front
()
->
uv
[
vModels
.
front
()
->
mesh
[
i
]
*
2
+
1
];
}
tempBufferData
.
push_back
(
tempVertex
);
}
glBindBuffer
(
GL_ARRAY_BUFFER
,
glui
U
VBufferID
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiV
ertex
BufferID
);
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
temp
UV
)
*
tempUV
.
size
(),
temp
UV
.
data
(),
sizeof
(
temp
BufferData
)
*
tempBufferData
.
size
(),
temp
BufferData
.
data
(),
GL_STATIC_DRAW
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment