Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mandelbrot-explorer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ильин Владимир Александрович
mandelbrot-explorer
Commits
76fdac15
Commit
76fdac15
authored
Feb 18, 2025
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
texture rendering working, but colors are broken
parent
0ef2756c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
11 deletions
+36
-11
mandelbrot
mandelbrot
+0
-0
mandelbrot.c
src/mandelbrot.c
+34
-11
mandelbrot.h
src/mandelbrot.h
+2
-0
No files found.
mandelbrot
View file @
76fdac15
No preview for this file type
src/mandelbrot.c
View file @
76fdac15
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_pixels.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_scancode.h>
#include <SDL2/SDL_surface.h>
...
...
@@ -80,6 +81,32 @@ calculate_set(Array *arr, int height, int width, ViewInfo view)
}
}
void
update_texture
(
App
*
app
,
Array
*
arr
)
{
void
*
pixels
;
int
pitch
;
if
(
SDL_LockTexture
(
app
->
texture
,
NULL
,
&
pixels
,
&
pitch
)
!=
0
)
{
fprintf
(
stderr
,
"Failed to lock texture: %s
\n
"
,
SDL_GetError
());
return
;
}
uint32_t
*
dst
=
pixels
;
Color
*
src
=
arr
->
pointer
;
for
(
int
y
=
0
;
y
<
app
->
win_height
;
y
++
)
{
for
(
int
x
=
0
;
x
<
app
->
win_width
;
x
++
)
{
Color
c
=
src
[
x
*
app
->
win_height
+
y
];
// Convert RGB to RGBA8888 format
*
dst
++
=
(
c
.
b
<<
0
)
|
(
c
.
g
<<
8
)
|
(
c
.
r
<<
16
)
|
(
255
<<
24
);
}
dst
+=
pitch
/
sizeof
(
uint32_t
)
-
app
->
win_width
;
}
SDL_UnlockTexture
(
app
->
texture
);
}
void
render_cl
(
Array
*
arr
,
App
*
app
,
ViewInfo
view
)
{
...
...
@@ -91,18 +118,10 @@ render_cl(Array *arr, App *app, ViewInfo view) {
arr
->
size
=
app
->
win_height
*
app
->
win_width
*
sizeof
(
Color
);
}
calculate_set
(
arr
,
app
->
win_height
,
app
->
win_width
,
view
);
update_texture
(
app
,
arr
);
for
(
int
x
=
0
;
x
<
app
->
win_width
;
x
++
)
{
for
(
int
y
=
0
;
y
<
app
->
win_height
;
y
++
)
{
SDL_SetRenderDrawColor
(
app
->
renderer
,
arr
->
pointer
[
x
*
app
->
win_height
+
y
].
r
,
arr
->
pointer
[
x
*
app
->
win_height
+
y
].
g
,
arr
->
pointer
[
x
*
app
->
win_height
+
y
].
b
,
255
);
SDL_RenderDrawPoint
(
app
->
renderer
,
x
,
y
);
}
}
SDL_RenderCopy
(
app
->
renderer
,
app
->
texture
,
NULL
,
NULL
);
}
...
...
@@ -156,6 +175,10 @@ main(void)
SDL_CreateRenderer
(
app
.
window
,
-
1
,
SDL_RENDERER_ACCELERATED
),
SDL_CreateTexture
(
app
.
renderer
,
SDL_PIXELFORMAT_RGBA8888
,
SDL_TEXTUREACCESS_STREAMING
,
SCREEN_WIDTH
,
SCREEN_HEIGHT
),
SCREEN_HEIGHT
,
SCREEN_WIDTH
};
...
...
src/mandelbrot.h
View file @
76fdac15
...
...
@@ -2,6 +2,7 @@
#define MANDELBROT_H
#include <SDL2/SDL.h>
#include <SDL2/SDL_render.h>
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
...
...
@@ -15,6 +16,7 @@ typedef struct {
typedef
struct
{
SDL_Window
*
window
;
SDL_Renderer
*
renderer
;
SDL_Texture
*
texture
;
int
win_height
;
int
win_width
;
}
App
;
...
...
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