7 changed files with 83 additions and 32 deletions
-
8Res/rgbcube.fs
-
12Res/rgbcube.vs
-
6model.cpp
-
9renderFramework.vcxproj
-
65renderFramework.vcxproj.filters
-
13scene.cpp
-
2shader.cpp
@ -0,0 +1,8 @@ |
|||||
|
#ifdef GL_ES |
||||
|
precision mediump float; |
||||
|
#endif |
||||
|
varying vec4 V_Color; |
||||
|
void main() |
||||
|
{ |
||||
|
gl_FragColor=V_Color; |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
#ifdef GL_ES |
||||
|
precision mediump float; |
||||
|
#endif; |
||||
|
attribute vec4 position; |
||||
|
uniform mat4 ModelMatrix; |
||||
|
uniform mat4 ViewMatrix; |
||||
|
uniform mat4 ProjectionMatrix; |
||||
|
varying vec4 V_Color; |
||||
|
void main(){ |
||||
|
V_Color = vec4(position.x + 0.5, position.y+0.5, position.z +0.5, 1.0); |
||||
|
gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * position; |
||||
|
} |
@ -1,13 +1,26 @@ |
|||||
#include "scene.h"
|
#include "scene.h"
|
||||
|
#include "utils.h"
|
||||
|
#include "model.h"
|
||||
|
|
||||
|
glm::mat4 viewMatrix, projectionMatrix; |
||||
|
glm::vec3 cameraPos(4.0f, 3.0f, 4.0f); |
||||
|
Model model; |
||||
void Init() |
void Init() |
||||
{ |
{ |
||||
|
model.Init("Res/Cube.obj"); |
||||
|
model.mShader->Init("Res/rgbcube.vs", "Res/rgbcube.fs"); |
||||
|
model.SetPosition(0.0f, 0.0f, 0.0f); |
||||
|
viewMatrix = glm::lookAt(cameraPos, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); |
||||
} |
} |
||||
|
|
||||
void SetViewPortSize(float width, float height) |
void SetViewPortSize(float width, float height) |
||||
{ |
{ |
||||
|
projectionMatrix = glm::perspective(50.0f, width/height, 0.1f, 1000.0f); |
||||
} |
} |
||||
|
|
||||
void Draw() |
void Draw() |
||||
{ |
{ |
||||
|
glClearColor(0.0f,0.0f,0.0f,1.0f); |
||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
||||
|
model.Draw(viewMatrix, projectionMatrix, cameraPos.x, cameraPos.y, cameraPos.z); |
||||
} |
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue