c++ – Why does my OpenGL program don’t draw anything after I set the textures?

I have a C++ program, that I’m doing for a university class, but I keep encountering a this problem.

This is my code:

This is the first part, where I call all the process for drawing an object.

//Sets the resources of the rendering object
obj.m_obj->SetResources(GetManager(), obj.m_useTextures);

// Sets the values stored for the shader
for (Values& v : m_values)
{
    switch (v.m_type)
    {
    case eDataType::BOOL:
        m_shaders.SetBool(v.m_uniform, *(bool*)v.m_data);
        break;
    case eDataType::INT:
        m_shaders.SetBool(v.m_uniform, *(int*)v.m_data);
        break;
    case eDataType::FLOAT:
        m_shaders.SetBool(v.m_uniform, *(float*)v.m_data);
        break;
    case eDataType::UINT:
        m_shaders.SetBool(v.m_uniform, *(unsigned int*)v.m_data);
        break;
    case eDataType::BOOL2:
    {
        bool* data = (bool*)v.m_data;
        m_shaders.SetBool2(v.m_uniform, data(0), data(1));
        break;
    }
    case eDataType::INT2:
    {
        int* data = (int*)v.m_data;
        m_shaders.SetInt2(v.m_uniform, data(0), data(1));
        break;
    }
    case eDataType::FLOAT2:
    {
        float* data = (float*)v.m_data;
        m_shaders.SetFloat2(v.m_uniform, data(0), data(1));
        break;
    }
    case eDataType::UNIT2:
    {
        unsigned int* data = (unsigned int*)v.m_data;
        m_shaders.SetUint2(v.m_uniform, data(0), data(1));
        break;
    }
    case eDataType::BOOL3:
    {
        bool* data = (bool*)v.m_data;
        m_shaders.SetBool3(v.m_uniform, data(0), data(1), data(2));
        break;
    }
    case eDataType::INT3:
    {
        int* data = (int*)v.m_data;
        m_shaders.SetInt3(v.m_uniform, data(0), data(1), data(2));
        break;
    }
    case eDataType::FLOAT3:
    {
        float* data = (float*)v.m_data;
        m_shaders.SetFloat3(v.m_uniform, data(0), data(1), data(2));
        break;
    }
    case eDataType::UINT3:
    {
        unsigned int* data = (unsigned int*)v.m_data;
        m_shaders.SetUint3(v.m_uniform, data(0), data(1), data(2));
        break;
    }
    case eDataType::BOOL4:
    {
        bool* data = (bool*)v.m_data;
        m_shaders.SetBool4(v.m_uniform, data(0), data(1), data(2), data(3));
        break;
    }
    case eDataType::INT4:
    {
        int* data = (int*)v.m_data;
        m_shaders.SetInt4(v.m_uniform, data(0), data(1), data(2), data(3));
        break;
    }
    case eDataType::FLOAT4:
    {
        float* data = (float*)v.m_data;
        m_shaders.SetFloat4(v.m_uniform, data(0), data(1), data(2), data(3));
        break;
    }
    case eDataType::UINT4:
    {
        unsigned int* data = (unsigned int*)v.m_data;
        m_shaders.SetUint4(v.m_uniform, data(0), data(1), data(2), data(3));
        break;
    }
    case eDataType::MAT:
    {
        glm::mat4* data = (glm::mat4*)v.m_data;
        m_shaders.SetMat4(v.m_uniform, *data);
    }
    }
}

// Sets the textures of the shader in order
int slot = 0;
for (InputTexture& it : m_inputTextures)
{
    GetManager()->ShaderSetInt(it.m_uniform, slot);

    // Uses GL_TEXTURE0 as base, and increment it with 'slot'
    // to GL_TEXTURE1, GL_TEXTURE2, etc., because its values
    // are consecutive.
    glActiveTexture(GL_TEXTURE0 + slot++);
    glBindTexture(GL_TEXTURE_2D, it.m_texture.getID());
}

// Draws the object 
obj.m_obj->Draw(GetManager(), obj.m_useTextures);

This is the ‘SetResources’ function:

SetMat4("model", glm::mat4(model._11, model._12, model._13, model._14,
                           model._21, model._22, model._23, model._24,
                           model._31, model._32, model._33, model._34,
                           model._41, model._42, model._43, model._44));

glPolygonMode(GL_FRONT_AND_BACK, m_topology);

And the Draw Function:

glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);

glDrawElements(GL_TRIANGLES, m_indicesCount, GL_UNSIGNED_INT, (const void*)0);

The ‘m_shader.Set***()’ just uses the respective OpenGL function that correspond to the data.

Before all of that I set the active shader

glUseProgram(m_ID);

And then set the render buffer and the frame buffer

// Bind the renderbuffer
glBindRenderbuffer(GL_RENDERBUFFER, m_depthStencil.getID());

    if (m_outputTextures.size() > 0)
    {
        GLenum* DrawBuffers = new GLenum(m_outputTextures.size());
        for (int i = 0; i < m_outputTextures.size(); i++)
        {
            // Bind the frame buffer (one of them, for now it's just the back buffer, so ID is 0)
            glBindFramebuffer(GL_FRAMEBUFFER, m_outputTextures(i).m_renderTarget->getID());

            // if the frame buffer needs to be clean (in this case is always), cleans it with the color given
            if (m_outputTextures(i).m_cleanRenderTarget)
            {
                glClearColor(m_outputTextures(i).m_clearColor(0) * m_outputTextures(i).m_clearColor(3), 
                             m_outputTextures(i).m_clearColor(1) * m_outputTextures(i).m_clearColor(3), 
                             m_outputTextures(i).m_clearColor(2) * m_outputTextures(i).m_clearColor(3), 
                             m_outputTextures(i).m_clearColor(3));
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            }

            // Set "renderedTexture" as our colour attachement #0 + i (as in the 'GL_Texture0 + slot' part)
            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, m_outputTextures(i).m_renderTarget->getTextureAtatchedID(), 0);

            // Adds the color attatchment to the array, so it knows it exists.
            DrawBuffers(i) = GL_COLOR_ATTACHMENT0 + i;
        }

        // Set the list of draw buffers.
        glDrawBuffers(m_outputTextures.size(), DrawBuffers);

        // Clean memory
        delete() DrawBuffers;
    }

The problem here is that, when I do it in this way, it doesn’t draw anything, but when I change the draw call to the end of the ‘SetResources’ function, it does draw something. But if I do it in that way, if there are more than one shader, the active shader draws with the information of the shader before it, and not its own.

Any clue of what it could be happening?

import – Is there already a program that analyzes THz-TDS data in Mathematica?

I plan to write a code that reads the time domain data(sample+reference), performs Fourier transforms, calculates transmissivity, solves the transfer function numerically, and gets complex refractive index and optical conductivity, does average, etc.
Since the THz time-domain spectroscopy (THz-TDS) technique is widely spread, I wonder maybe there is already a public code written in Mathematica that I can use as a start. I searched but I did not find any. I know that in MATLAB, there are solutions, but I like how Mathematica can handle complex-valued functions, so I would like to use it to analyze my data. I am a new user of this language.
Any ideas, links are welcome!

networking – Program to continuously check availability of internet connection c#

I have a C# program to check if a hard coded host is available and if not, waits 5 seconds then checks again (this is a loop). How can it be enhanced?

using System;
using System.Net.NetworkInformation;
using System.Windows.Forms;

namespace trial17
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        static Ping p = new Ping();
        static string host = "8.8.8.8";
        static byte() buffer = new byte(32);
        static int timeout = 1000;
        static PingOptions po = new PingOptions();
        static PingReply pr;
        static bool load = false;
//plays media if connected        
System.Media.SoundPlayer player = new System.Media.SoundPlayer("media file path");

        private void Form5_Load(object sender, EventArgs e)
        {
            try
            {
                Show();
                conn();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        async void conn()
        {
            try
            {
                pr = p.Send(host, timeout, buffer, po);
                if (pr.Status == IPStatus.Success)
                {
                    player.Play();
//label updated after connection
                    label1.Text = "Connected";
                }
                else
                {
                    await System.Threading.Tasks.Task.Delay(200);
                    conn();
                }
            }
            catch (Exception) {
            }
        }
    }
}

beginner – Possible improvements to window swallowing program?

I have written a small program that swallows windows. It works in X.org using the xcb library. This is my first rust program but I have lots of other programming experience.

Any general improvements are great, but a specific problem I’ve been having is that if the program exits too quickly (child process is short) there’s a chance the parent window isn’t remapped. I have gotten around this by using the sleep function, but this is only a quick fix and slows the program down noticeably.

I have tried many different features of xcb like set_input_focus, change_window_attribute and wait_for_event among others. I have also tried different logical solutions like running map_window multiple times or running the command through sh -c.

Here is the source code:

extern crate xcb;
use std::{env, process, thread, time};

fn main() {
    let (conn, _screen_num) = xcb::Connection::connect(None).unwrap();
    let win = xcb::get_input_focus(&conn).get_reply().unwrap().focus();
    let args: Vec<String> = env::args().collect();
    let mut command = process::Command::new(&args(1));
    command.args(&args(2 .. args.len()));

    xcb::unmap_window(&conn, win);
    conn.flush();
    let stat: i32 = command.status().unwrap().code().unwrap();
    xcb::map_window(&conn, win);
    conn.flush();

    thread::sleep(time::Duration::from_millis(10));

    process::exit(stat);
}

And the GitHub link: https://github.com/EmperorPenguin18/gobble

optimization – Non-convex linear program optimisation with infinite number of OR constraints

I am aware that when we have a linear problem subject to OR constraints, the LP would be a non-convex optimisation problem. For example,

${x = 0}$ OR ${1<=x<=2}$.

I could not find much explanation on the internet concerning a detailed explanation of this situation. I’d appreciate if anyone could explain this in more detail.

Similar questions in other sites:

https://math.stackexchange.com/questions/4158912/infinite-number-of-or-constraints-in-linear-programming

https://stackoverflow.com/questions/50987517/expressing-an-or-constraint-in-linear-programming

python – Tic Tac Toe program

I have created a simple Tic-Tac-Toe program. Can someone please review it and let me know where I can improve.

Here we can play against computer. Program start by putting ‘X’ at the center that is at the position 5. Then ask user to enter number from available position and then assign ‘O’ on selected position. There are four possible verdicts: the game should continue, or the game ends with a tie, your win, or the computer’s win;

import random

def board():
    "Creating Board dictionary"
    dic_board = {}
    v = 1
    for i in range(3):
        for j in range(3):
            k = str(i) + str(j)
            dic_board(k) = v
            v += 1
    update_board(dic_board)

def draw_board(board):
    """Draw board"""
    for i in range(3):
        print('+' + '-' * 5 + '+' + '-' * 5 + '+' + '-' * 5 + '+', end='')
        print()
        print('|' + ' ' * 5 + '|' + ' ' * 5 + '|' + ' ' * 5 + '|')
        for j in range(3):
            k = str(i) + str(j)
            print('| ' + str(board(k)) + ' ' * 3, end='')
        print('|')
        print('|' + ' ' * 5 + '|' + ' ' * 5 + '|' + ' ' * 5 + '|')
    print('+' + '-' * 5 + '+' + '-' * 5 + '+' + '-' * 5 + '+', end='')
    print()

def update_board(board):
    """the first move belongs to the computer -
    it always puts its first 'X' in the middle of the board that is at 5;"""
    total_moves = 0
    flag = True  #Flag = True for computer's move and False for user's move
    while total_moves < 9 :
        available_num = (v for k, v in board.items() if v not in ('X','O'))
        if flag :
            if total_moves == 0:
                update_moves(board, 'Comp', 5)
                flag = False
                sign = 'X'
                draw_board(board)
            else:
                num = random.choice(available_num)
                update_moves(board, 'Comp', num)
                flag = False
                sign = 'X'
                draw_board(board)
        else:
            try:
                s = str(available_num)
                val = int(input('Select Number '+ s + ': '))
                update_moves(board, 'User', val)
                flag = True
                sign = 'O'
            except:
                print('Invalid Input!!')
                continue
        total_moves += 1

        v = victory(board,sign)

        if v:
            print(v)
            if sign == 'O' :
                draw_board(board)
            break
    else :
        print('Tie !!')
        print('Game Over!!')




def update_moves(board, moves,val):
    "Updating borad as per input"
    key_to_update = (k for k, v in board.items() if v == val)
    if moves == 'Comp':
        board(key_to_update(0)) = 'X'
    elif moves == 'User':
        board(key_to_update(0)) = 'O'
    return board

def victory(board,sign):
    message = ''
    message = row_status(board,sign,message)
    message = column_status(board,sign,message)
    message = digonals_status(board,sign,message)
    return message



def row_status(board,sign,message):
    """checking for Horizontal row"""
    if board('00') == board('01') == board('02') == sign or 
            board('10') == board('11') == board('12') == sign or 
            board('20') == board('21') == board('22') == sign:
        if sign == 'X':
            message = 'computer win !!'
        elif sign == 'O':
            message = 'Your win !!'
    return message

def column_status(board,sign,message):
    """checking for verticle column """
    if board('00') == board('10') == board('20') == sign or 
            board('01') == board('11') == board('21') == sign or 
            board('02') == board('12') == board('22') == sign:
        if sign == 'X':
                message = 'computer win !!'
            elif sign == 'O':
                message = 'Your win !!'
        return message
    
    def digonals_status(board,sign,message):
        """checking for digonals """
        if board('00') == board('11') == board('22') == sign or 
           board('02') == board('11') == board('20') == sign :
            if sign == 'X':
                message = 'computer win !!'
            elif sign == 'O':
                message = 'Your win !!'
        return message

print(board())

mysql – database schema design for online program with questions required to answer

Background

There are 4 online programs(A, B, C, D) for users to attend.

Users are only allowed to attend one program at the same time.
They can attend other programs given that they have no ongoing program.

In the program, there are around 50 pages in each program and some pages require user to answer the question. For example, page 3 may have 3 multiple-choice questions, page 11 have 1 fill-in-the blank question

users need to answer some questions which may be multiple choice or fill-in the blank questions, which are opinion-based(no correct answer).
They can navigate to previous/next page for answering questions.

Also, I need to record the last page users visited so that they can come back anytime.

Database Schema Design

I’ve made a initial design for all tables I need.

User 
-userId(primary key)
-username
-password
...
Program
-programId(primary key)
-type (A/B/C/D)
-currentPage
-startDate
-endDate
Question
-questionId(primary key)
-type(multipleChoice/fillInTheBlank)
-questionText
Question-Answer
-Id(primary key)
-questionId(foreign key of Question table)
-answerText

Above Schema is all I can think of, I have no idea how to manage the relationship between above table.

Would Anyone provide some ideas to me?

downloading – How can I download a file with the Google Drive program directly to my phone’s SD card?


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




javascript – Idea for using user local installed program in web application ASP.NET

javascript – Idea for using user local installed program in web application ASP.NET – Software Engineering Stack Exchange

How to check the output of a program in black-box testing?

As part of a black-box testing activity, I would like to check the executable I’m testing generates a binary file that responds to its specifications given a specific input.
I’m wondering how I can check that.

I have two solutions in mind but each of them has some drawbacks:

  1. Compare bit by bit the output with a binary of reference. If the two files are equal, the test passes
  2. Parse the generated binary file and check if it contains the expected data

The advantage of the solution 1 is there is no need of an external tool to check the output is correct. However, how to generate the reference? Most of the time, the tested executable will be used to generate the binary of reference. It makes the test pointless because we are testing it against itself (it may have a purpose in regression testing). Another inconvenience I see with this solution is we will need to rewrite all the tests each time a single bit of the output changes.

On the other hand, with the solution 2, we will only need to modify the parser if the specification changes (plus eventually some tests related to this change). However, where does this parser come from? Is it a parser dedicated for testing this binary? In this case, how can we be sure the parser is correct? Or is the parser part of another binary included in our software application? In this case, our tests are dependent on another part of the software. If there is a regression in it, our tests will fail despite the fact the issue is elsewhere.

As you can see, there are pros and cons for both of the solutions and I’m not able to determine which is the best choice in which conditions. Which solution would you choose? Or is there a third solution I have not imagined?

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123