C++ SDL 2, drawing a rectangle

Learn Programming - Thu, 09/20/2018 - 23:47

I've been using SDL with C++ for a while now but all I can really do is create a window. I'm trying to learn how to draw a rectangle using SDL's draw rect functions but I can't find any good information on how to do it. Most of the time it doesn't work and in the rare event that it does there is no information on how it works.
Here is my current code for creating a window:

include <iostream> include <SDL2/SDL.h>

const int WIDTH = 1200, HEIGHT = 750;

int main(int argc, const char * argv[])

// Check for successful initialization of SDL if (SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { std::cout << "SDL could not initialize! SDL Error: " << SDL_GetError() << std::endl; } // Creating the window SDL_Renderer* renderer; SDL_Window* window; SDL_Surface* screen; window = SDL_CreateWindow("New Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI); if (window == nullptr) { std::cout << "Could not create window! SDL error: " << SDL_GetError() << std::endl; return EXIT_FAILURE; } renderer = SDL_CreateRenderer(window, -1, 0); if (renderer == nullptr) { std::cout << "Could not create renderer! SDL error" << SDL_GetError() << std::endl; return EXIT_FAILURE; } SDL_SetRenderDrawColor(renderer, 60, 70, 20, 30); //just a random colour ^ screen = SDL_GetWindowSurface(window); SDL_RenderClear(renderer); SDL_RenderPresent(renderer); SDL_UpdateWindowSurface(window); SDL_Event windowEvent; while ( true ) { if (SDL_PollEvent( &windowEvent ) ) { if ( SDL_QUIT == windowEvent.type ) { break; } } } SDL_DestroyWindow( window ); SDL_Quit( ); return EXIT_SUCCESS;


Note: this is not the exact same as my original code, not everything there is necessary

If anyone thinks they can explain it to me it would be much appreciated

submitted by /u/Hyddra-
[link] [comments]

Question about programming

Learn Programming - Thu, 09/20/2018 - 23:45

The short version of the question I have is, what program languages do what, and if I want to get into game development what languages should I learn, and what college courses should I look into, and what colleges are good for the courses. (Although it is a bit early to be looking into college) A little bit about me to help you out (IDK if this will help) I am 14, I am in 9th grade, currently I am doing online school and learning Python through BYU. I love games and have a passion to make them and get into the industry, some of my favorite games are: Destiny, Dark Souls, and Overwatch.

submitted by /u/PiggybackPeak4
[link] [comments]

Lives counter c#

Learn Programming - Thu, 09/20/2018 - 23:42

Hey guys,

I am starting learning code on c#. One of the small projects is to construct a lives counter with small heart pictures. ie

int lives = 5

Quite game when no lives left.

Have a score somewhere on the screen.

Any ideas on how to start? Ie how to I draw the number of picture of objects with depending on the lives value?

How do I show the score on the screen? ie with label object?

Any advise and assistance is welcome.

Thanks so much

submitted by /u/ninifrog
[link] [comments]

How long to get good at Java?

Learn Programming - Thu, 09/20/2018 - 23:42

Sorry if it's a silly question... I'm 54 years old and I have been programming since my dad bought an Altair 8800. I've done professional C/C++, python, perl, visual basic. For the past 15 years I've mostly specialized in DA stuff... Leaning to the programming side in Oracle and SQL Server. I started doing Java in the late 90's but have not done it since really.

Anyways my question is... How long would it take for me to learn to compete with professional Java programers? None of the concepts are foreign to me, it's just the explosion of tools etc that seems a little daunting. A month of full time study? Six months? Any advice appreciated.

submitted by /u/rocketboy1998
[link] [comments]

DevOps and DRY

Programming - Thu, 09/20/2018 - 23:41
Categories: Programming

Has anyone discovered their love for programming through college courses?

Learn Programming - Thu, 09/20/2018 - 23:20

What I'm asking here is - Is there anyone out there who entered into a college programming course with ZERO previous programming experience or investigation and suddenly discovered their passion for it?

I'm a college programming instructor and we're coming to the end of the first run of this program. It's been hard and we've lost more than a few for a variety of reasons. It's a 1200-hour night program and that's a long time when you're working during the day and maybe have a family and other obligations. Most had no previous experience playing around with code and sometimes approached it like a college course they needed to complete.

I'm honestly questioning if this kind of college setting is the right place to teach full-on in-depth software development (SQL, C#, HTML / CSS, JavaScript and all the trimmings). The reason for my question is because most of the stories I've heard and my own experience is that people who are going to be successful programmers and developers mostly discover it on their own even if they later take courses. I believe the problems with this program began with inadequate screening of candidates but I'm also wondering if I could have done more to inspire any of those who left.

submitted by /u/CatsOnTheKeyboard
[link] [comments]

How did you learn to program in your first 6 months?

Learn Programming - Thu, 09/20/2018 - 23:18

What was your mentality like? What was the struggle like? What resources did you use to learn?

submitted by /u/ConditionalDew
[link] [comments]

Using C++ to read in an audio file (mp3), and split it into chunks at a time interval?

Learn Programming - Thu, 09/20/2018 - 23:17

I have no idea where to start/what libraries to use to help process mp3 files, but I would like to be able to have the user input an mp3, then look up its BPM via a 3rd party API (most likely the Spotify API, until I get around to figuring out FTT), then split the mp3 into distinct chunks every four beats for further processing and comparison.

Where would I go about learning how to do this?

submitted by /u/I_AM_BEAR_AMA
[link] [comments]

Defining functions in function parameters?

Learn Programming - Thu, 09/20/2018 - 23:11

My background in C++ and then Java always taught me that calling a function should look something like,

foo(dataType parameter1, dataType parameter2, ...) ;

But I have noticed that it seems to be fairly commonplace to jam a function definition into a parameter's spot. I regularly try to avoid this at all costs (it's one of the reasons I gave up on Javascript), but I am going through a tutorial for how to make Android apps and I am seeing it again.

From a naive perspective, this looks pointless and absolutely terrible. But seeing as it happens a lot, I can only assume I'm missing something and that I am wrong. I'd appreciate if people could help me understand this practice better.

What exactly is going on here? What is the benefit of defining a function as a parameter, rather than just defining it normally?

submitted by /u/19Ant91
[link] [comments]

Writing notes when learning to program?

Learn Programming - Thu, 09/20/2018 - 22:39

How should I take notes when it comes to an online bootcamp?

submitted by /u/gicksta
[link] [comments]

Email subscription with daily scheduled email... need help

Learn Programming - Thu, 09/20/2018 - 22:27

I'm building a web app written with Python back end using the Flask framework, hosted on AWS elastic beanstalk. It is essentially a website that provides daily workouts for people to follow. I have it all set up so that the new workout is posted the night before, and the 10 most recent workouts are shown on the website. I have two questions:

  1. I want people to be able to subscribe so that they get daily emails with that day's workout. So I have a "subscribe" form, but it's not hooked up. Not sure where I should store the name and emails of subscribers. I tried to get a mySQLdb going, but I was not able to set it up correctly.
  2. Related to the first question, I need to schedule emails to be sent from my domain name, say []( I haven't bough a domain name yet, because I want the service to offer a free email account with the domain name purchase. I saw that Amazon's Route 53 doesn't offer a free email account. Say that I get all that squared away, how would I schedule such emails? And I need to format the emails in HTML, which I am reading that it is kind of a headache. Simple HTML though, with a picture, two columns, and an unsubscribe button.

Anyways, I feel so stuck doing this cuz I've been trying to get a mySQL server set up but I don't even know if that's what I need. Any tips would be appreciated.

submitted by /u/Endyd
[link] [comments]

Finite Automata: Questions about DFA's and NDFA's

Learn Programming - Thu, 09/20/2018 - 22:20

From what I understand, the number of a NDFA's possible state transitions from one state to another state are not necessarily equal to one and only one given an input X.

Suppose I have an NDFA that has 2 states: A and B, and all possible input values are {0, 1}. Final state is B, and start state is A.

Here are the possible transitions:

Given input 1, transition to B.

Since input of 0 in either state transitions to null state, how can this be converted to a DFA if each state in a DFA must transition to another state given some input value {0,1}?

Also, I'm having trouble understanding the concept of a state. Is the whole point of a state, in conjunction with other states, used to determine the rule for a language?

How is it that an NDFA can be converted to a DFA. I don't understand how a single state can be a set of states. That part just doesn't make sense! One state containing more than one state? I just dont get it.

submitted by /u/Angoram
[link] [comments]

HTML/CSS Help with moving things and margins.

Learn Programming - Thu, 09/20/2018 - 22:12

So I have this code that is supposed to create a grey to black gradient with an rgb color swirl in the middle of the page.

My code did everything except move my box to the middle of the page. Can you guys help me?

Here is an image of what my code looks like now:

Here is my index.html:

<!DOCTYPE html> <html> <head> <link href="|Raleway:100,200,600,700" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="style.css"> <link href="" rel="stylesheet"> <link rel="icon" href=""> </head> <body> <div class="shadow"></div> </body> </html>

and here is my Style.css:

body { background: #000; font-family: 'Raleway', sans-serif; margin: 200; padding: 200; position: relative; } h1 { font-family: Raleway; color: #FFFFFF; } .shadow { position: relative; width: 400px; height: 250px; margin: 200 auto 0 ; background: linear-gradient(0deg,#000,#262626); } .shadow:before, .shadow:after { content: ''; position: absolute; top: -2px; left: -2px; background: linear-gradient(45deg,#fb0094,#0000ff,#00ff00,#ffff00,#ff0000,#fb0094,#0000ff,#00ff00,#ffff00,#ff0000); background-size: 400%; z-index: -1; width: calc(100% + 4px); height: calc(100% + 4px); animation: animate 20s linear infinite; } .shadow:after { filter: blur(20px) } @keyframes animate { 0% { background-position: 0 0; } 50% { background-position: 300% 0; } 100% { background-position: 0 0; } }

So. I think it may be my margins in my body tag in Style.css

Keep in mind I am new to HTML and CSS. Thanks again! Also feel free to reply with whatever other bits of knowledge you need on the situation.

submitted by /u/ExistNotYT
[link] [comments]

How to hosting a queue messaging service on nginx

Learn Programming - Thu, 09/20/2018 - 21:58

NGINX is a lightweight, high-performance web server designed for high-traffic use cases. It handles all the client request by specify the directive and route to other service. Nginx act as proxy server to load balancing the request to other service which is/is not part of nginx.

One of the best nginx feature is, it can

  • create multiple workers process
  • each worker can handle multiple request concurrently
  • Each worker can communicate and sharing data via using share memory

What if the nginx able to hosting the queue messaging service and sharing the queue container on multiple workers ? Yes it is for now

ngx_lfqueue module is a nginx module, it is lock free concurrent queue service, it act as a share memory lock free queue in nginx. It design for enqueue and dequeue the message via nginx.


There are 4 commands in this module

ngx_lfqueue_memory_allocate Example to configure the ngx_lfqueue in nginx.conf
main config scope (1 argument) allocate the suitable share memory size for all the queue.

main config scope (1 argument) init or reload the queue with a queue name, if the queue name existed on backup data, it will load from backup data.

main config scope (2 arguments) backup the data with special unique split key and file path, if file path not mentioned, it will stored under same directory of nginx config file.

location config scope (1 argument) target which queue name to process data enqueue or dequeue.
POST METHOD — Enqueue request body data
GET METHOD — Dequeue queue message
HEAD METHOD — Get the queue Info
Ref :

Example to configure the ngx_lfqueue in nginx.conf

# nginx.conf main conf scope http { ngx_lfqueue_memory_allocate 10m; ngx_lfqueue_name q1; ngx_lfqueue_name q2; ngx_lfqueue_name q3; ngx_lfqueue_backup |@| /tmp/ngx_lfqueue_data.txt; … server { .... location /processQueue { ngx_lfqueue_target q1; } location /processQueueWithArgVariable { ngx_lfqueue_target arg_targetQueue; } } }

Calling the service via using http call

for enqueue

POST /processQueue HTTP/1.1 Host: Cache-Control: no-cache Postman-Token: 858bacc8-4826-9d8e-5ec5-fde220351b5d {"Data":"MESSAGE 1......."}

For dequeue

GET /processQueue HTTP/1.1 Host: Cache-Control: no-cache Postman-Token: a0f89290-981a-2e18-cd99-40fa7fe734a0

For queue info

HEAD /processQueue HTTP/1.1 Host: Cache-Control: no-cache Postman-Token: 487251d4-51e9-33ee-58cf-343f259df27b

How to install ngx_lfqueue module into nginx
Ref :

Active Developer Support
Please do not hesitate to contact []( for any queries or development improvement

submitted by /u/ciminika
[link] [comments]

Should programming paradigms be mutually exclusive in an application?

Learn Programming - Thu, 09/20/2018 - 21:54

When building an application or program, should I try to write in as 'pure' as possible for a given programming paradigm?

E.g. Build an app strictly using object orientated programming

Or should I (given that I'm using a multi-paradigm language), pick and choose depending on what's best for a task?

E.g. An app that uses a mix of OOP/Functional/Procedural/Declarative/Imperative/etc code

submitted by /u/projectyang1
[link] [comments]

How do you deal with feelings of failure?

Learn Programming - Thu, 09/20/2018 - 21:33

I don't know if this is the correct forum for this but I just want to know. I'm 19 and currently working for minimum wage at a restaurant while also pursing a A.S. in Computer Programming. While going to school full time I also work on freecodecamp because I want to start freelance web development while still in college. I have been doing it for 4 months but despite my college courses and freecodecamp sometimes I feel like I can't master programming. I also feel a immense wave of inadequacy where I feel I won't be able to get a job or work in this field of work. How do you deal with this feeling of failure or inadequacy while trying to gain the skills to land your jobs?

Also I sometimes question whether I am doing enough work, is there something else I should be doing as well? I'm learning java and cyber security in my A.S. Classes plus I'm learning front end web development in freecodecamp, are there some youtube channels or something else I should work on to help me in my past.

Thanks to all who answer in advance.

submitted by /u/DarkStarAlastor
[link] [comments]

Generic Computer Science Question

Learn Programming - Thu, 09/20/2018 - 21:32

I know this is "r/learnprogramming" but I have a computer science question and this seemed like the best place to ask it. How would one go about making a program that does something. Wait! I mean, take Chrome for example I know there isn't some built in function .getWebsiteandLoad("") and even if there was how would someone program that function? Other than math and outputing words on a console using python or C++ I am at a loss how somone would make a computer do something other than math and cout.

submitted by /u/BeigeGnat
[link] [comments]