Jump to content
  • Advertisement

rbkblhjy

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

105 Neutral

About rbkblhjy

  • Rank
    Newbie
  1. Hi all. Strange thigs happening on my screen. When i enable depth buffer i saw only clear color of render target view but when i disdable it everything is ok. Why? There is my code of D3D initialization. Where is my mistake, please help. (sorry for my english). DXGI_MODE_DESC backBufferDesc; DXGI_SWAP_CHAIN_DESC swapChainDesc; D3D11_TEXTURE2D_DESC textureDesc; D3D_FEATURE_LEVEL featureLevel; IDXGIDevice* pDXGIDevice = nullptr; IDXGIAdapter* pDXGIAdapter = nullptr; IDXGIFactory* pDXGIFactory = nullptr; ID3D11Texture2D* pTmpTexture = nullptr; UINT deviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED; UINT qualityLevel = 0; HRESULT hr; // Device + device context. #if defined(_DEBUG) deviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, deviceFlags, nullptr, 0, D3D11_SDK_VERSION, &mPDevice, &featureLevel, &mPDeviceContext); if(FAILED(hr)) { MessageBox(nullptr, L"Device creation failed!", L"Error", MB_OK); return false; } if(featureLevel != D3D_FEATURE_LEVEL_11_0) { MessageBox(nullptr, L"Your device doesn't support D3D11!", L"Error", MB_OK); return false; } // Sample desc. hr = mPDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, 4, &qualityLevel); if(FAILED(hr)) { mSampleDesc.Count = 1; mSampleDesc.Quality = 0; } else { mSampleDesc.Count = 4; mSampleDesc.Quality = qualityLevel - 1; } // Swap chain. backBufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; backBufferDesc.Height = WINDOW->getHeight(); backBufferDesc.RefreshRate.Numerator = 60; backBufferDesc.RefreshRate.Denominator = 1; backBufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; backBufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; backBufferDesc.Width = WINDOW->getWidth(); swapChainDesc.BufferCount = 1; swapChainDesc.BufferDesc = backBufferDesc; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.Flags = 0; swapChainDesc.OutputWindow = WINDOW->getHwnd(); swapChainDesc.SampleDesc = mSampleDesc; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Windowed = true; mPDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&pDXGIDevice); pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&pDXGIAdapter); pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&pDXGIFactory); hr = pDXGIFactory->CreateSwapChain(mPDevice, &swapChainDesc, &mPSwapChain); pDXGIFactory->MakeWindowAssociation(WINDOW->getHwnd(), DXGI_MWA_NO_WINDOW_CHANGES); RELEASE_COM(pDXGIFactory) RELEASE_COM(pDXGIAdapter) RELEASE_COM(pDXGIDevice) if(FAILED(hr)) { MessageBox(nullptr, L"Swap chain creation failed!", L"Error", MB_OK); return false; } // Render target view. mPSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pTmpTexture); hr = mPDevice->CreateRenderTargetView(pTmpTexture, nullptr, &mPRenderTargetView); RELEASE_COM(pTmpTexture) if(FAILED(hr)) { MessageBox(nullptr, L"RTV Creation failed!", L"Error", MB_OK); return false; } // Depth stencil view. textureDesc.Width = WINDOW->getWidth(); textureDesc.Height = WINDOW->getHeight(); textureDesc.MipLevels = 1; textureDesc.ArraySize = 1; textureDesc.Format = DXGI_FORMAT_D16_UNORM; textureDesc.SampleDesc.Count = 1; textureDesc.SampleDesc.Quality = 0; textureDesc.Usage = D3D11_USAGE_DEFAULT; textureDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; textureDesc.CPUAccessFlags = 0; textureDesc.MiscFlags = 0; hr = mPDevice->CreateTexture2D(&textureDesc, nullptr, &mPDepthStencilBuffer); if(FAILED(hr)) { MessageBox(nullptr, L"Depth Stencil buffer creation failed!", L"Error", MB_OK); return false; } hr = mPDevice->CreateDepthStencilView(mPDepthStencilBuffer, nullptr, &mPDepthStencilView); if(FAILED(hr)) { MessageBox(nullptr, L"Depth stencil creatrion failed!", L"Error", MB_OK); return false; } // Viewport. mViewport.Height = WINDOW->getHeight(); mViewport.MaxDepth = 1.0f; mViewport.MinDepth = 0.0f; mViewport.TopLeftX = 0.0f; mViewport.TopLeftY = 0.0f; mViewport.Width = WINDOW->getWidth(); // Init shaders... preconfigureRendering(); // Create input layout DXGI_FORMAT verticesFormat[3] = { DXGI_FORMAT_R32G32B32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32B32_FLOAT }; UINT offsets[3] = { 0, 12, 20 }; std::string semanticNames[3] = { std::string("POSITION"), std::string("TEXCOORD"), std::string("NORMAL") }; for(int i = 0; i < 3; ++i) { mLayoutDesc[i].AlignedByteOffset = offsets[i]; mLayoutDesc[i].Format = verticesFormat[i]; mLayoutDesc[i].InputSlot = 0; mLayoutDesc[i].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; mLayoutDesc[i].InstanceDataStepRate = 0; mLayoutDesc[i].SemanticIndex = 0; mLayoutDesc[i].SemanticName = semanticNames[i].c_str(); } if(FAILED(mPDevice->CreateInputLayout(mLayoutDesc, 3, mShader.getVertexShaderBytecode()->GetBufferPointer(), mShader.getVertexShaderBytecode()->GetBufferSize(), &mPInputLayout))) { MessageBox(nullptr, L"Can't create Input Layout!", L"Error", MB_OK); return false; } // Setup. mPDeviceContext->RSSetViewports(1, &mViewport); mPDeviceContext->OMSetRenderTargets(1, &mPRenderTargetView, mPDepthStencilView); mPDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); mPDeviceContext->IASetInputLayout(mPInputLayout);
  2. rbkblhjy

    Why triangle is not drawing?

    tonemgub Thank you very much for your help.
  3. rbkblhjy

    Why triangle is not drawing?

    tonemgub Thank you for your ansver! But my program wasn't supposed to have texCoord.  I put values from the first programm to the second with 4 floatin point values per vertex and it work!. (My english is not so good, i'm from Ukraine).
  4. rbkblhjy

    Why triangle is not drawing?

    Rewrote programm and it works. Why? Please help.   #include <iostream> #include <glew.h> #include <glfw3.h> GLfloat clearColor[] = { 1.0f, 1.0f, 1.0f, 1.0f }; GLuint vertexShader, fragmentShader, shaderProgram, vbo; GLfloat vertices[] = { 0.0f, 0.5f,    0.5f, 0.0f,   -0.5f, 0.0f }; GLuint CreateShader(GLenum type, const GLchar* src); GLuint CreateProgram(GLuint vShader, GLuint fShader); void InitScene() { glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); GLchar vsrc[] = { "#version 430 core  \n"  "layout(location = 0) in vec4 position; \n"  "void main() {                          \n"  "gl_Position = position;                \n"  "}                                      \n" }; GLchar fsrc[] = { "#version 430 core   \n"  "out vec4 resColor;   \n"  "void main() {   \n"  "resColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);\n"  "}   \n" }; vertexShader   = CreateShader(GL_VERTEX_SHADER, vsrc); fragmentShader = CreateShader(GL_FRAGMENT_SHADER, fsrc); shaderProgram  = CreateProgram(vertexShader, fragmentShader); if(shaderProgram == -1)  { std::getchar(); exit(1); } glDeleteShader(vertexShader); glDeleteShader(fragmentShader); } void ResizeCallback(GLFWwindow* wnd, int width, int height) { glViewport(0, 0, width, height); } void Draw() { glBindBuffer(GL_ARRAY_BUFFER, vbo); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); glUseProgram(shaderProgram); glClearBufferfv(GL_COLOR, 0, clearColor); glDrawArrays(GL_TRIANGLES, 0, 3); glFlush(); glBindBuffer(GL_ARRAY_BUFFER, 0); glUseProgram(0); } void Terminate() { glDeleteBuffers(1, &vbo); glDeleteProgram(shaderProgram); } int main(int argc, char** argv) { if(!glfwInit()) return 0; GLFWwindow* wnd = glfwCreateWindow(640, 480, "Hello triangle", nullptr, nullptr); if(!wnd)  { glfwTerminate(); return 0; } glfwMakeContextCurrent(wnd); glewExperimental = true; if(glewInit() != GLEW_OK) { glfwTerminate(); return 0; } glfwSetWindowSizeCallback(wnd, ResizeCallback); InitScene(); while(!glfwWindowShouldClose(wnd)) { Draw(); glfwSwapBuffers(wnd); glfwPollEvents(); } Terminate(); glfwDestroyWindow(wnd); glfwTerminate(); return 0; } GLuint CreateProgram(GLuint vShader, GLuint fShader) { GLuint p = glCreateProgram(); glAttachShader(p, vShader); glAttachShader(p, fShader); glLinkProgram(p); GLint status; glGetProgramiv(p, GL_LINK_STATUS, &status); if(status == GL_FALSE) { glGetProgramiv(p, GL_INFO_LOG_LENGTH, &status); GLchar* infoLog = new GLchar[status + 1]; glGetProgramInfoLog(p, status, nullptr, infoLog); std::cout << "Program error: \n" << infoLog << "\n"; return -1; } return p; } GLuint CreateShader(GLenum type, const GLchar* src) { GLuint s      = glCreateShader(type); GLint  status = 0; glShaderSource(s, 1, &src, nullptr); glCompileShader(s); glGetShaderiv(s, GL_COMPILE_STATUS, &status); if(status == GL_FALSE) { glGetShaderiv(s, GL_INFO_LOG_LENGTH, &status); GLchar* infoLog = new GLchar[status + 1]; glGetShaderInfoLog(s, status, nullptr, infoLog); switch(type) { case GL_VERTEX_SHADER:   std::cout << "Vertex shader error: \n";   break; case GL_FRAGMENT_SHADER: std::cout << "Fragment shader error: \n"; break; } std::cout << infoLog << "\n"; delete []infoLog; return -1; } return s; }
  5. rbkblhjy

    Why triangle is not drawing?

    HappyCoder I see only clear color.   dpadam450 -10 didn't work.  For what projection matrix? Points already in clip space.
  6. rbkblhjy

    Why triangle is not drawing?

    Renew my shader create function. GLuint CreateProgram(GLuint vs, GLuint fs) { GLuint prog = glCreateProgram(); GLint status; glAttachShader(prog, vs); glAttachShader(prog, fs); glLinkProgram(prog); glGetProgramiv(prog, GL_LINK_STATUS, &status); glDetachShader(prog, vs); glDetachShader(prog, fs); if(status == GL_FALSE)  { return -1; } return prog; }
  7. Hi everybody! Today i've started to learn OpenGL and have some problems with it. I tried to draw a triangle but i failed? Can't understand the problem, please help newbie)   CPP CODE   #include <glew.h> #include <freeglut.h> #include <iostream> #include <fstream> #include <string> using namespace std; GLuint vbo, shader, vs, ps; GLfloat verts[] = {     0.75f, 0.75f, 0.0f, 1.0f,     0.75f, -0.75f, 0.0f, 1.0f,     -0.75f, -0.75f, 0.0f, 1.0f, }; GLuint CreateShader(GLenum type, const char* src); GLuint CreateProgram(GLuint vs, GLuint ps); void init() { glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), verts, GL_STATIC_DRAW); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); ifstream f1, f2; string   v,  p, tmp; f1.open("v.vert"); f2.open("f.frag"); if(!f1.is_open() || !f2.is_open()) { glDeleteBuffers(1, &vbo); exit(1); } while(!f1.eof()) { std::getline(f1, tmp); v += tmp + "\n"; tmp.clear(); } while(!f2.eof()) { std::getline(f2, tmp); p += tmp + "\n"; tmp.clear(); } vs     = CreateShader(GL_VERTEX_SHADER, v.c_str()); ps     = CreateShader(GL_FRAGMENT_SHADER, p.c_str()); shader = CreateProgram(vs, ps); if(shader == -1)  { glDeleteBuffers(1, &vbo); glDeleteShader(vs); glDeleteShader(ps); exit(1); } glUseProgram(shader); glDeleteShader(vs); glDeleteShader(ps); f1.close(); f2.close(); } void display() { glClearColor(1.0f, 1.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glDrawArrays(GL_TRIANGLES, 0, 3); glFlush(); glutSwapBuffers(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(512, 512); glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_CORE_PROFILE); glutCreateWindow(argv[0]); if(glewInit()) { return 0; } init(); glutDisplayFunc(display); glutMainLoop(); return 0; } GLuint CreateShader(GLenum type, const GLchar* src) { GLuint res = glCreateShader(type); GLint compileStatus; glShaderSource(res, 1, &src, nullptr); glCompileShader(res); glGetShaderiv(res, GL_COMPILE_STATUS, &compileStatus); if(compileStatus == GL_FALSE) { GLint   infoLength; GLchar *infoLog = nullptr; glGetShaderiv(res, GL_INFO_LOG_LENGTH, &infoLength); infoLog = new GLchar[infoLength + 1]; glGetShaderInfoLog(res, infoLength, nullptr, infoLog); cout << infoLog << endl; delete []infoLog; } return res; } GLuint CreateProgram(GLuint vs, GLuint fs) { GLuint prog = glCreateProgram(); GLint status; glAttachShader(prog, vs); glAttachShader(prog, ps); glLinkProgram(prog); glGetProgramiv(prog, GL_LINK_STATUS, &status); glDetachShader(prog, vs); glDetachShader(prog, fs); if(status == GL_FALSE)  { return -1; } return prog; }   Vertex shader   #version 430 core layout(location = 0) in vec4 position; void main() { gl_Position = position; }   Fragment Shader   #version 430 core out vec4 outColor; void main() { outColor = vec4(1.0f, 1.0f, 1.0f, 1.0f); }  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!