Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
OpenGL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
C-Fu
OpenGL
Commits
e5490b94
Commit
e5490b94
authored
Nov 08, 2016
by
Anakin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
collect all texture data and give it to the shader later,
solid color works, texture crash
parent
9c7691df
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
49 deletions
+80
-49
MshViewer/Header/OpenGLController.h
MshViewer/Header/OpenGLController.h
+9
-0
MshViewer/Source/OpenGlController.cpp
MshViewer/Source/OpenGlController.cpp
+71
-49
No files found.
MshViewer/Header/OpenGLController.h
View file @
e5490b94
...
...
@@ -5,6 +5,7 @@
#include <glm\glm.hpp>
#include <vector>
#include "Object.h"
#include "Texture.h"
#define VERTEX_INDEX_XYZ 0
#define VERTEX_INDEX_UV 1
...
...
@@ -23,6 +24,13 @@ struct Vertex {
GLfloat
uv
[
2
];
};
struct
textureData
{
bool
alpha
;
std
::
uint32_t
width
;
std
::
uint32_t
height
;
const
GLvoid
*
data
;
};
class
OpenGLController
{
////////////////////////////////////////////////////////////////////////////////////////////
...
...
@@ -65,6 +73,7 @@ private:
// data
std
::
vector
<
Modl
*>
vModels
;
std
::
vector
<
textureData
*>
vTextures
;
// transformation =========================
//values
...
...
MshViewer/Source/OpenGlController.cpp
View file @
e5490b94
...
...
@@ -41,6 +41,13 @@ OpenGLController::~OpenGLController()
delete
cursor
->
vertex
;
delete
cursor
;
}
while
(
!
vTextures
.
empty
())
{
textureData
*
cursor
=
vTextures
.
back
();
vTextures
.
pop_back
();
delete
cursor
;
}
}
...
...
@@ -104,8 +111,13 @@ void OpenGLController::processInit()
exit
(
1
);
}
// get some shader IDs
gluiMatrixID
=
glGetUniformLocation
(
gluiShaderPrgmID
,
"MVP"
);
gluiSamplerID
=
glGetUniformLocation
(
gluiShaderPrgmID
,
"textureSampler"
);
// generate texture
glGenTextures
(
1
,
&
gluiTextureID
);
glBindTexture
(
GL_TEXTURE_2D
,
gluiTextureID
);
}
void
OpenGLController
::
startGLFW
()
...
...
@@ -266,7 +278,7 @@ void OpenGLController::updateScene()
void
OpenGLController
::
loadMsh
(
const
char
*
path
)
{
// get
data
// get
all models
try
{
Object
obj
(
path
);
...
...
@@ -278,55 +290,9 @@ void OpenGLController::loadMsh(const char * path)
exit
(
1
);
}
glGenTextures
(
1
,
&
gluiTextureID
);
glBindTexture
(
GL_TEXTURE_2D
,
gluiTextureID
);
try
{
////TODO: for all
if
(
vModels
.
front
()
->
texture
==
""
)
throw
std
::
invalid_argument
(
"no texture name"
);
std
::
string
tempPath
=
path
;
while
(
tempPath
.
back
()
!=
'/'
&&
tempPath
.
back
()
!=
'\\'
)
tempPath
.
pop_back
();
TextureTGA
tempTex
(
std
::
string
(
tempPath
+
vModels
.
front
()
->
texture
).
c_str
());
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
tempTex
.
hasAlpha
()
?
GL_RGBA
:
GL_RGB
,
tempTex
.
getWidth
(),
tempTex
.
getHeight
(),
0
,
tempTex
.
hasAlpha
()
?
GL_BGRA
:
GL_BGR
,
GL_UNSIGNED_BYTE
,
tempTex
.
getData
().
data
()
);
}
catch
(
std
::
invalid_argument
e
)
{
GLubyte
solidColor
[
4
]
=
{
255
,
0
,
0
,
255
};
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
1
,
1
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
(
const
GLvoid
*
)
solidColor
);
}
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR_MIPMAP_LINEAR
);
glGenerateMipmap
(
GL_TEXTURE_2D
);
////TODO: for all
// collect vertex data of all models
std
::
vector
<
Vertex
>
tempBufferData
;
for
(
auto
&
it
:
vModels
)
{
for
(
unsigned
int
i
=
0
;
i
<
it
->
meshSize
;
i
++
)
...
...
@@ -351,6 +317,7 @@ void OpenGLController::loadMsh(const char * path)
}
}
// fill the buffer
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiVertexBufferID
);
glBufferData
(
GL_ARRAY_BUFFER
,
...
...
@@ -360,4 +327,59 @@ void OpenGLController::loadMsh(const char * path)
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
// get textures
for
(
auto
&
it
:
vModels
)
{
textureData
*
tempData
=
new
textureData
;
try
{
if
(
it
->
texture
==
""
)
throw
std
::
invalid_argument
(
"no texture name"
);
std
::
string
tempPath
=
path
;
while
(
tempPath
.
back
()
!=
'/'
&&
tempPath
.
back
()
!=
'\\'
)
tempPath
.
pop_back
();
TextureTGA
tempTex
(
std
::
string
(
tempPath
+
vModels
.
front
()
->
texture
).
c_str
());
tempData
->
alpha
=
tempTex
.
hasAlpha
();
tempData
->
width
=
tempTex
.
getWidth
();
tempData
->
height
=
tempTex
.
getHeight
();
tempData
->
data
=
tempTex
.
getData
().
data
();
}
catch
(
std
::
invalid_argument
e
)
{
GLubyte
solidColor
[
4
]
=
{
0
,
0
,
255
,
255
};
tempData
->
alpha
=
true
;
tempData
->
width
=
1
;
tempData
->
height
=
1
;
tempData
->
data
=
(
const
GLvoid
*
)
solidColor
;
}
vTextures
.
push_back
(
tempData
);
}
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
vTextures
.
front
()
->
alpha
?
GL_RGBA
:
GL_RGB
,
vTextures
.
front
()
->
width
,
vTextures
.
front
()
->
height
,
0
,
vTextures
.
front
()
->
alpha
?
GL_BGRA
:
GL_BGR
,
GL_UNSIGNED_BYTE
,
vTextures
.
front
()
->
data
);
// set some texture parameters
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_REPEAT
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR_MIPMAP_LINEAR
);
glGenerateMipmap
(
GL_TEXTURE_2D
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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