Gstreamer1.0 missing element : v4l2h264enc in Qualcomm RB5 - gstreamer

Before starting I am aware there are almost same questions with what I will ask, but since the question is almost board specific I will still ask.
I have a Qualcomm RB5 Robotic Vision Kit which has ov9282 camera. I configured a lighter Ubuntu 18.04, and kernel version is 5.15.0(5.15.0-qcomlt-arm64). I have built the gstreamer1.0(1.20.2) from source code. The meson command I used:
meson configure build -Dgst-plugins-bad:v4l2codecs=enabled -Dgst-plugins-good:v4l2=enabled -Dgst-plugins-good:v4l2-gudev=enabled
As you can see, I enabled all v4l2 related plugins and elements, and it seems I was successful partially. After meson, I executed ninja install to create symlinks. So far I haven't encountered with a problem. when I prompt gst-inspect-1.0 video4linux2, it shows elements in the .so file.
root#linaro-developer:~# gst-inspect-1.0 video4linux2
Plugin Details:
Name video4linux2
Description elements for Video 4 Linux
Filename /usr/local/lib/aarch64-linux-gnu/gstreamer-1.0/libgstvideo4linux2.so
Version 1.20.2.1
License LGPL
Source module gst-plugins-good
Binary package GStreamer Good Plug-ins git
Origin URL Unknown package origin
v4l2deviceprovider: Video (video4linux2) Device Provider
v4l2h264dec: V4L2 H264 Decoder
v4l2h265dec: V4L2 H265 Decoder
v4l2mpeg2dec: V4L2 MPEG2 Decoder
v4l2radio: Radio (video4linux2) Tuner
v4l2sink: Video (video4linux2) Sink
v4l2src: Video (video4linux2) Source
v4l2vp8dec: V4L2 VP8 Decoder
v4l2vp9dec: V4L2 VP9 Decoder
9 features:
+-- 8 elements
+-- 1 device providers
However, in the build directory I can see gstv4l2h264enc.c.o file which I need.
root#linaro-developer:/home/linaro/gstreamer/build/subprojects/gst-plugins-good/sys/v4l2/libgstvideo4linux2.so.p# ls
gstv4l2.c.o gstv4l2colorbalance.c.o gstv4l2h263enc.c.o gstv4l2h265enc.c.o gstv4l2mpeg4enc.c.o gstv4l2src.c.o gstv4l2videoenc.c.o gstv4l2vp9codec.c.o tunernorm.c.o
gstv4l2allocator.c.o gstv4l2deviceprovider.c.o gstv4l2h264codec.c.o gstv4l2jpegenc.c.o gstv4l2object.c.o gstv4l2transform.c.o gstv4l2vidorient.c.o gstv4l2vp9enc.c.o v4l2-utils.c.o
gstv4l2bufferpool.c.o gstv4l2element.c.o gstv4l2h264enc.c.o gstv4l2mpeg2codec.c.o gstv4l2radio.c.o gstv4l2tuner.c.o gstv4l2vp8codec.c.o tuner.c.o v4l2_calls.c.o
gstv4l2codec.c.o gstv4l2fwhtenc.c.o gstv4l2h265codec.c.o gstv4l2mpeg4codec.c.o gstv4l2sink.c.o gstv4l2videodec.c.o gstv4l2vp8enc.c.o tunerchannel.c.o
Moreover, I viewed the content of the .so file to be sure I built the gstv4l2 module correctly. Output of nm -D libgstvideo4linux2.so, I can see the encoding parameters in the file.
U GST_CAT_DEFAULT
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w __cxa_finalize#GLIBC_2.17
U __errno_location#GLIBC_2.17
U __getauxval#GLIBC_2.17
w __gmon_start__
U _gst_caps_features_memory_system_memory
U _gst_caps_type
U _gst_debug_category_new
U _gst_debug_get_category
U _gst_debug_min
U _gst_debug_register_funcptr
U _gst_element_error_printf
U _gst_fraction_range_type
U _gst_fraction_type
U _gst_int_range_type
U _gst_structure_type
U _gst_value_list_type
U clock_gettime#GLIBC_2.17
U close#GLIBC_2.17
U dup#GLIBC_2.17
U g_ascii_strcasecmp
U g_ascii_strdown
U g_ascii_strtod
U g_ascii_table
U g_ascii_tolower
U g_assertion_message_expr
U g_clear_error
U g_cond_broadcast
U g_cond_clear
U g_cond_init
U g_cond_signal
U g_cond_wait
U g_datalist_clear
U g_datalist_id_get_data
U g_datalist_id_set_data_full
U g_enum_register_static
U g_error_new_literal
U g_flags_register_static
U g_free
U g_get_real_time
U g_getenv
U g_idle_source_new
U g_intern_static_string
U g_list_delete_link
U g_list_find_custom
U g_list_foreach
U g_list_free
U g_list_free_full
U g_list_insert_sorted_with_data
U g_list_prepend
U g_list_remove
U g_list_reverse
U g_list_sort
U g_log
U g_main_context_new
U g_main_context_push_thread_default
U g_main_context_ref
U g_main_context_unref
U g_main_loop_new
U g_main_loop_quit
U g_main_loop_ref
U g_main_loop_run
U g_main_loop_unref
U g_malloc
U g_malloc0
U g_mutex_lock
U g_mutex_unlock
U g_object_class_install_property
U g_object_get
U g_object_new
U g_object_ref
U g_object_ref_sink
U g_object_set
U g_object_unref
U g_once_init_enter
U g_once_init_leave
U g_param_spec_boolean
U g_param_spec_boxed
U g_param_spec_enum
U g_param_spec_flags
U g_param_spec_int
U g_param_spec_string
U g_param_spec_uint
U g_path_get_basename
U g_quark_from_string
U g_quark_to_string
U g_queue_clear
U g_queue_foreach
U g_queue_push_tail
U g_rec_mutex_lock
U g_rec_mutex_unlock
U g_return_if_fail_warning
U g_set_error_literal
U g_signal_connect_data
U g_signal_emit
U g_signal_emit_by_name
U g_signal_handler_block
U g_signal_handler_disconnect
U g_signal_handler_unblock
U g_signal_new
U g_slice_alloc
U g_slice_free1
U g_slist_foreach
U g_slist_free
U g_slist_insert_sorted
U g_source_attach
U g_source_set_callback
U g_source_unref
U g_str_equal
U g_strcmp0
U g_strconcat
U g_strdup
U g_strdup_printf
U g_strerror
U g_thread_join
U g_thread_new
U g_type_add_interface_static
U g_type_check_instance_is_a
U g_type_check_value
U g_type_check_value_holds
U g_type_class_adjust_private_offset
U g_type_class_peek_parent
U g_type_from_name
U g_type_interface_peek
U g_type_name
U g_type_query
U g_type_register_static
U g_type_register_static_simple
U g_udev_client_new
U g_udev_client_query_by_subsystem
U g_udev_device_get_device_file
U g_udev_device_get_property
U g_udev_device_get_property_as_int
U g_udev_device_get_sysfs_path
U g_value_copy
U g_value_dup_string
U g_value_get_boolean
U g_value_get_enum
U g_value_get_int
U g_value_get_string
U g_value_get_uint
U g_value_init
U g_value_set_boolean
U g_value_set_enum
U g_value_set_flags
U g_value_set_int
U g_value_set_string
U g_value_set_uint
U g_value_take_string
U g_value_transform
U g_value_unset
U gst_allocator_get_type
U gst_atomic_queue_length
U gst_atomic_queue_new
U gst_atomic_queue_pop
U gst_atomic_queue_push
U gst_atomic_queue_unref
U gst_base_sink_wait_preroll
U gst_base_src_get_allocator
U gst_base_src_get_buffer_pool
U gst_base_src_negotiate
U gst_base_src_set_caps
U gst_base_src_set_format
U gst_base_src_set_live
U gst_base_transform_get_buffer_pool
U gst_base_transform_get_type
U gst_base_transform_is_passthrough
U gst_base_transform_set_passthrough
U gst_base_transform_set_qos_enabled
U gst_buffer_add_video_meta_full
U gst_buffer_append_memory
U gst_buffer_copy_into
U gst_buffer_copy_region
U gst_buffer_fill
U gst_buffer_get_size
U gst_buffer_get_video_meta
U gst_buffer_map
U gst_buffer_n_memory
U gst_buffer_new
U gst_buffer_new_allocate
U gst_buffer_peek_memory
U gst_buffer_pool_acquire_buffer
U gst_buffer_pool_config_add_option
U gst_buffer_pool_config_get_allocator
U gst_buffer_pool_config_get_params
U gst_buffer_pool_config_has_option
U gst_buffer_pool_config_set_allocator
U gst_buffer_pool_config_set_params
U gst_buffer_pool_config_validate_params
U gst_buffer_pool_get_config
U gst_buffer_pool_get_type
U gst_buffer_pool_is_active
U gst_buffer_pool_set_active
U gst_buffer_pool_set_config
U gst_buffer_pool_set_flushing
U gst_buffer_resize
U gst_buffer_unmap
U gst_caps_append
U gst_caps_append_structure
U gst_caps_append_structure_full
U gst_caps_can_intersect
U gst_caps_copy_nth
U gst_caps_features_copy
U gst_caps_features_is_any
U gst_caps_features_is_equal
U gst_caps_features_new
U gst_caps_fixate
U gst_caps_foreach
U gst_caps_get_features
U gst_caps_get_size
U gst_caps_get_structure
U gst_caps_intersect
U gst_caps_intersect_full
U gst_caps_is_any
U gst_caps_is_empty
U gst_caps_is_equal
U gst_caps_is_fixed
U gst_caps_is_subset
U gst_caps_is_subset_structure_full
U gst_caps_map_in_place
U gst_caps_merge
U gst_caps_new_empty
U gst_caps_normalize
U gst_caps_set_features
U gst_caps_set_value
U gst_caps_simplify
U gst_caps_truncate
U gst_clock_get_time
U gst_color_balance_channel_get_type
U gst_color_balance_get_type
U gst_core_error_quark
U gst_debug_log
U gst_device_get_type
U gst_device_provider_class_set_static_metadata
U gst_device_provider_device_add
U gst_device_provider_device_remove
U gst_device_provider_get_type
U gst_device_provider_register
U gst_dmabuf_allocator_new
U gst_dmabuf_memory_get_fd
U gst_element_class_add_pad_template
U gst_element_class_set_metadata
U gst_element_class_set_static_metadata
U gst_element_factory_make
U gst_element_get_type
U gst_element_message_full
U gst_element_post_message
U gst_element_register
U gst_fd_allocator_alloc
U gst_flow_get_name
U gst_is_dmabuf_memory
U gst_memory_get_sizes
U gst_memory_init
U gst_memory_is_type
U gst_memory_resize
U gst_message_new_qos
U gst_mini_object_copy
U gst_mini_object_get_qdata
U gst_mini_object_is_writable
U gst_mini_object_make_writable
U gst_mini_object_ref
U gst_mini_object_replace
U gst_mini_object_set_qdata
U gst_mini_object_steal_qdata
U gst_mini_object_unref
U gst_object_get_name
U gst_object_ref
U gst_object_ref_sink
U gst_object_sync_values
U gst_object_unref
U gst_pad_get_allowed_caps
U gst_pad_get_current_caps
U gst_pad_get_pad_template_caps
U gst_pad_get_task_state
U gst_pad_pause_task
U gst_pad_peer_query
U gst_pad_peer_query_caps
U gst_pad_query_caps
U gst_pad_start_task
U gst_pad_stop_task
U gst_pad_template_new
U gst_plugin_add_dependency
U gst_plugin_register_static
000000000000aa50 T gst_plugin_video4linux2_get_desc
000000000000aa60 T gst_plugin_video4linux2_register
U gst_poll_add_fd
U gst_poll_fd_ctl_pri
U gst_poll_fd_ctl_read
U gst_poll_fd_ctl_write
U gst_poll_fd_has_error
U gst_poll_fd_has_pri
U gst_poll_fd_init
U gst_poll_free
U gst_poll_new
U gst_poll_set_flushing
U gst_poll_wait
U gst_push_src_get_type
U gst_query_add_allocation_meta
U gst_query_add_allocation_param
U gst_query_add_allocation_pool
U gst_query_find_allocation_meta
U gst_query_get_n_allocation_params
U gst_query_get_n_allocation_pools
U gst_query_new_allocation
U gst_query_parse_allocation
U gst_query_parse_caps
U gst_query_parse_nth_allocation_meta
U gst_query_parse_nth_allocation_param
U gst_query_parse_nth_allocation_pool
U gst_query_set_caps_result
U gst_query_set_latency
U gst_query_set_nth_allocation_param
U gst_query_set_nth_allocation_pool
U gst_resource_error_quark
U gst_static_caps_get
U gst_stream_error_quark
U gst_structure_copy
U gst_structure_fixate_field
U gst_structure_fixate_field_nearest_fraction
U gst_structure_fixate_field_nearest_int
U gst_structure_fixate_field_string
U gst_structure_foreach
U gst_structure_free
U gst_structure_get_fraction
U gst_structure_get_int
U gst_structure_get_name
U gst_structure_get_string
U gst_structure_get_uint
U gst_structure_get_value
U gst_structure_has_field
U gst_structure_has_name
U gst_structure_map_in_place
U gst_structure_n_fields
U gst_structure_new
U gst_structure_new_empty
U gst_structure_nth_field_name
U gst_structure_remove_field
U gst_structure_remove_fields
U gst_structure_set
U gst_structure_set_value
U gst_structure_take_value
U gst_structure_to_string
U gst_type_mark_as_plugin_api
U gst_uri_error_quark
U gst_uri_handler_get_type
U gst_util_fraction_multiply
U gst_util_greatest_common_divisor
U gst_util_uint64_scale_int
U gst_value_compare
U gst_value_fraction_subtract
U gst_value_get_fraction_denominator
U gst_value_get_fraction_numerator
U gst_value_get_structure
U gst_value_intersect
U gst_value_is_fixed
U gst_value_list_append_and_take_value
U gst_value_list_append_value
U gst_value_list_get_size
U gst_value_list_get_value
U gst_value_set_fraction
U gst_value_set_fraction_range_full
U gst_value_set_int_range_step
U gst_value_set_structure
U gst_value_subtract
U gst_video_alignment_reset
U gst_video_calculate_display_ratio
U gst_video_codec_frame_unref
U gst_video_codec_state_ref
U gst_video_codec_state_unref
U gst_video_colorimetry_is_equal
U gst_video_colorimetry_to_string
U gst_video_decoder_drop_frame
U gst_video_decoder_finish_frame
U gst_video_decoder_get_buffer_pool
U gst_video_decoder_get_frame
U gst_video_decoder_get_oldest_frame
U gst_video_decoder_get_type
U gst_video_decoder_negotiate
U gst_video_decoder_proxy_getcaps
U gst_video_decoder_set_latency
U gst_video_decoder_set_output_state
U gst_video_decoder_set_packetized
U gst_video_encoder_allocate_output_buffer
U gst_video_encoder_finish_frame
U gst_video_encoder_get_frame
U gst_video_encoder_get_oldest_frame
U gst_video_encoder_get_output_state
U gst_video_encoder_get_type
U gst_video_encoder_negotiate
U gst_video_encoder_set_latency
U gst_video_encoder_set_output_state
U gst_video_format_to_string
U gst_video_frame_copy
U gst_video_frame_map
U gst_video_frame_unmap
U gst_video_info_align_full
U gst_video_info_from_caps
U gst_video_info_init
U gst_video_info_set_interlaced_format
U gst_video_info_to_caps
U gst_video_interlace_mode_to_string
U gst_video_meta_api_get_type
U gst_video_meta_get_plane_height
U gst_video_meta_set_alignment
U gst_video_orientation_get_type
U gst_video_sink_get_type
U ioctl#GLIBC_2.17
U memcpy#GLIBC_2.17
U memset#GLIBC_2.17
U mmap64#GLIBC_2.17
U munmap#GLIBC_2.17
U open64#GLIBC_2.17
U read#GLIBC_2.17
U stat64#GLIBC_2.33
U strcmp#GLIBC_2.17
U strcpy#GLIBC_2.17
U strerror#GLIBC_2.17
U strlen#GLIBC_2.17
U strncpy#GLIBC_2.17
As the last step it is frustruating to see Gstreamer1.0 cannot find v4l2h264enc or any other encoding elements. The output of
root#linaro-developer:/home/linaro/gstreamer/build/subprojects/gst-plugins-good/sys/v4l2# gst-inspect-1.0 v4l2h264enc
No such element or plugin 'v4l2h264enc'
So where I am missing, any help, comment, or guidance will be appreciated a lot.

See which encoders are currently active on your gstreamer setup:
gst-inspect-1.0 | grep '264.*enc'
Maybe you could use one of the listed encoders instead.
See a similar issue on the Raspberry Pi at https://github.com/raspberrypi/linux/issues/3974

Related

How do I get ocamlformat to ignore a specific comment

I have a comment in my code that indicates what is contained inside of a two-dimensional array:
(**
I
N H
F A
A B L A T E
B A I N T
R T H O U G H
A E A
S T
I N C I N E R A T E
V
E
*)
Due to its nature, it needs to be formatted exactly like this. However, whenever I run ocamlformat, it gets reformatted to look like this:
(** I N H F A A B L A T E B A I N T R T H O U G H A E A S T I N C I
N E R A T E V E *)
How do I fix this? The closest I've been able to get without affecting anything else is this:
let _ =
()
(*
I
N H
F A
A B L A T E
B A I N T
R T H O U G H
A E A
S T
I N C I N E R A T E
V
E
*)
[#ocamlformat "disable"]
But that's not very satisfying. This comment is supposed to be attached to a top-level item, but I can't do that with this method b/c then ocamlformat will be disabled for the entire item. I can't figure out how to disable the comment formatting only.
You can use [##ocamlformat "wrap-comments=false"] to disable only the comment-wrapping feature,
let _ =
()
(*
I
N H
F A
A B L A T E
B A I N T
R T H O U G H
A E A
S T
I N C I N E R A T E
V
E
*)
[##ocamlformat "wrap-comments=false"]
You can also disable it in .ocamlformat, but since it is already disabled by default, I think it was the intention to have it. You can also disable the feature on a module level, using [###ocamlformat "wrap-comments=false"] at the beginning of your file.
As a side note, if you want ocamldoc to preserve the look of the comment in the generated documentation, you should also wrap it in the verbatim tag, e.g., the following will be rendered verbatim,
(**
{v
If P, then Q.
Not Q.
Therefore, not P.
v}
*)

Demo response different from runtime response

I'm trying to use the Google Cloud Vision API to OCR this image:
I'm using the following code the make the request:
const resp = await fetch(
`https://vision.googleapis.com/v1/images:annotate?key=${KEY}`, {
method: 'POST',
body: JSON.stringify({
requests: [{
image: {content: encoded},
features: [{type: "TEXT_DETECTION"}],
}]
}),
});
This works but there is some information missing from the result. If we look at the text field:
Dog Search
D G O OD D ODG O O D D O
O D O O G G G D O D G OG G
OGD GOGD GO G GO G D
D D D G D DO DOO G D O O
O DGOGG D O O G G O O D
DOG
Here's that visualized:
There are boxes around the characters which were recognized. But, if we put this image into the gcv demo application, we get this instead:
And this is what text looks like:
Dog Search
D GOOD D 0 D GOOD DO
0 D 0 0 G G G DOD GO GG
o G O G D 0 0 D G 0 0 D D D
D G D o o o G G o o G D Go
0 G D G O G D G O G G O G D
D D D G D DO DO O G D 0 0
O D GO G G D 0 0 G G 0 0 D
DOG
Here's a gist with the requests + responses. I'm authenticating using a API token.
Why are the responses different? The requests are slightly different but not in a way which should affect the output. Right?

Loaded obj model flickers and crashes application

I'm trying to load model from obj file and display it in OpenGL 2.0 but I have two problems.
Loaded model sometimes flickers and crashes my application randomly.
I have no idea what causes exception because I don't have even a stacktrace.
I only have "Frame not in module" and message:
Exception thrown at 0x000000CE25E7FF68 in Clock.exe: 0xC0000005: Access violation reading location 0x000000CE26640000.
Do you have any idea what is wrong? Code? File?
ObjLoader.h:
#pragma once
#include <vector>
using namespace std;
typedef struct _vertex {
float x, y, z;
} Vertex;
typedef struct _face {
unsigned int v, vn;
} Face;
struct ObjModel
{
vector<Vertex> Vertices;
vector<Vertex> Normals;
vector<vector<Face>> Faces;
};
class ObjLoader
{
public:
ObjModel LoadObjModel(const char* filePath);
private:
void ProcessIndices(ObjModel &model);
void ProcessLine(string &dataType, stringstream &ss, ObjModel &model);
Vertex ObjLoader::GetVertex(stringstream &ss);
vector<Face> ObjLoader::GetFaces(stringstream &ss);
};
ObjLoader.cpp:
#include "ObjLoader.h"
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
ObjModel ObjLoader::LoadObjModel(const char* filePath)
{
ObjModel model;
fstream in(filePath);
string line;
while (std::getline(in, line))
{
if (line.empty())
{
continue;
}
string dataType = line.substr(0, 2);
line = line.substr(2, line.size() - 2);
if (line[0] == ' ')
{
line = line.substr(1, line.size() - 1);
}
stringstream ss(line);
ProcessLine(dataType, ss, model);
}
ProcessIndices(model);
return model;
}
void ObjLoader::ProcessLine(string &dataType, stringstream &ss, ObjModel &model)
{
if (dataType == "v ")
{
model.Vertices.push_back(GetVertex(ss));
}
else if (dataType == "vn")
{
model.Normals.push_back(GetVertex(ss));
}
else if (dataType == "f ")
{
vector<Face> faces = GetFaces(ss);
model.Faces.push_back(faces);
}
}
Vertex ObjLoader::GetVertex(stringstream &ss)
{
Vertex vertex;
ss >> vertex.x >> vertex.y >> vertex.z;
return vertex;
}
vector<Face> ObjLoader::GetFaces(stringstream &ss)
{
vector<Face> faces;
string s;
while (getline(ss, s, ' '))
{
Face face;
int a, b;
sscanf(s.c_str(), "%d//%d", &a, &b);
face.v = a;
face.vn = b;
faces.push_back(face);
}
return faces;
}
void ObjLoader::ProcessIndices(ObjModel &model)
{
ObjModel temp;
temp.Vertices = vector<Vertex>();
temp.Normals = vector<Vertex>();
for (int i = 0; i < model.Faces.size(); i++)
{
for (int j = 0; j < model.Faces[i].size(); j++)
{
unsigned int vertexIndex = model.Faces[i][j].v - 1;
unsigned int normalIndex = model.Faces[i][j].vn - 1;
Vertex vertex = model.Vertices[vertexIndex];
Vertex normal = model.Normals[normalIndex];
temp.Vertices.push_back(vertex);
temp.Normals.push_back(vertex);
}
}
model.Vertices = temp.Vertices;
model.Normals = temp.Normals;
}
Displaying model:
float *vertices, *normals;
vertices = &model.Vertices[0].x;
normals = &model.Normals[0].x;
glEnable(GL_NORMALIZE);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, sizeof(float) * 4,normals);
glDrawArrays(GL_TRIANGLES, 0, model.Vertices.size());
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
Obj file:
v -0.048773 -0.250000 -1.004804
v -0.048773 0.250000 -1.004804
v 0.243863 0.250000 -0.975982
v 0.243863 -0.250000 -0.975982
v 0.784410 -0.250000 -0.156029
v 1.004804 -0.250000 -0.048773
v 0.975982 -0.250000 0.243863
v 0.738899 -0.250000 0.306062
v 0.664991 -0.250000 0.444333
v 0.744991 -0.250000 0.676016
v 0.517686 -0.250000 0.862560
v 0.306062 -0.250000 0.738899
v 0.156029 -0.250000 0.784410
v 0.048772 -0.250000 1.004804
v -0.243863 -0.250000 0.975981
v -0.306062 -0.250000 0.738898
v -0.444333 -0.250000 0.664991
v -0.676017 -0.250000 0.744991
v -0.862561 -0.250000 0.517685
v -0.738899 -0.250000 0.306061
v -0.784411 -0.250000 0.156028
v -0.293088 -0.250000 -0.006913
v -0.287323 -0.250000 0.051614
v -0.270251 -0.250000 0.107892
v -0.242528 -0.250000 0.159758
v -0.205220 -0.250000 0.205219
v -0.159759 -0.250000 0.242528
v -0.107893 -0.250000 0.270251
v -0.051615 -0.250000 0.287323
v 0.006912 -0.250000 0.293088
v 0.065440 -0.250000 0.287323
v 0.121718 -0.250000 0.270251
v 0.173584 -0.250000 0.242528
v 0.219045 -0.250000 0.205220
v 0.256353 -0.250000 0.159759
v 0.284076 -0.250000 0.107892
v 0.301148 -0.250000 0.051615
v 0.306913 -0.250000 -0.006913
v 0.306062 -0.250000 -0.738899
v 0.444333 -0.250000 -0.664991
v 0.676016 -0.250000 -0.744991
v 0.862560 -0.250000 -0.517686
v 0.738899 -0.250000 -0.306062
v 0.301148 -0.250000 -0.065440
v 0.284076 -0.250000 -0.121718
v 0.256353 -0.250000 -0.173584
v 0.219045 -0.250000 -0.219045
v 0.173584 -0.250000 -0.256353
v 0.121718 -0.250000 -0.284076
v 0.065440 -0.250000 -0.301148
v 0.006913 -0.250000 -0.306913
v -0.051614 -0.250000 -0.301148
v -0.107892 -0.250000 -0.284077
v -0.159758 -0.250000 -0.256354
v -0.205219 -0.250000 -0.219045
v -0.242528 -0.250000 -0.173584
v -0.270251 -0.250000 -0.121718
v -0.287323 -0.250000 -0.065440
v -1.004804 -0.250000 0.048772
v -0.975981 -0.250000 -0.243864
v -0.738898 -0.250000 -0.306063
v -0.664991 -0.250000 -0.444334
v -0.744990 -0.250000 -0.676017
v -0.517685 -0.250000 -0.862561
v -0.306061 -0.250000 -0.738899
v -0.156028 -0.250000 -0.784411
v -0.156028 0.250000 -0.784411
v -0.306061 0.250000 -0.738899
v -0.517685 0.250000 -0.862561
v -0.744990 0.250000 -0.676017
v -0.664991 0.250000 -0.444334
v -0.738898 0.250000 -0.306063
v -0.975981 0.250000 -0.243864
v -1.004804 0.250000 0.048772
v -0.784411 0.250000 0.156028
v -0.738899 0.250000 0.306061
v -0.862561 0.250000 0.517685
v -0.676017 0.250000 0.744991
v -0.444333 0.250000 0.664991
v -0.306062 0.250000 0.738898
v -0.243863 0.250000 0.975981
v 0.048772 0.250000 1.004804
v 0.156029 0.250000 0.784410
v 0.006912 0.250000 0.293088
v -0.051615 0.250000 0.287323
v -0.107893 0.250000 0.270251
v -0.159759 0.250000 0.242528
v -0.205220 0.250000 0.205219
v -0.242528 0.250000 0.159758
v -0.270251 0.250000 0.107892
v -0.287323 0.250000 0.051614
v -0.293088 0.250000 -0.006913
v -0.287323 0.250000 -0.065440
v -0.270251 0.250000 -0.121718
v -0.242528 0.250000 -0.173584
v -0.205219 0.250000 -0.219045
v -0.159758 0.250000 -0.256354
v -0.107892 0.250000 -0.284077
v -0.051614 0.250000 -0.301148
v 0.006913 0.250000 -0.306913
v 0.306062 0.250000 -0.738899
v 0.065440 0.250000 -0.301148
v 0.121718 0.250000 -0.284076
v 0.173584 0.250000 -0.256353
v 0.219045 0.250000 -0.219045
v 0.256353 0.250000 -0.173584
v 0.284076 0.250000 -0.121718
v 0.301148 0.250000 -0.065440
v 0.306913 0.250000 -0.006913
v 0.301148 0.250000 0.051615
v 0.284076 0.250000 0.107892
v 0.256353 0.250000 0.159759
v 0.219045 0.250000 0.205220
v 0.173584 0.250000 0.242528
v 0.121718 0.250000 0.270251
v 0.065440 0.250000 0.287323
v 0.306062 0.250000 0.738899
v 0.517686 0.250000 0.862560
v 0.744991 0.250000 0.676016
v 0.664991 0.250000 0.444333
v 0.738899 0.250000 0.306062
v 0.975982 0.250000 0.243863
v 1.004804 0.250000 -0.048773
v 0.784410 0.250000 -0.156029
v 0.738899 0.250000 -0.306062
v 0.862560 0.250000 -0.517686
v 0.676016 0.250000 -0.744991
v 0.444333 0.250000 -0.664991
vn 0.0980 0.0000 -0.9952
vn 0.0000 -1.0000 -0.0000
vn -0.8992 0.0000 -0.4376
vn 0.0000 1.0000 0.0000
vn 0.9673 0.0000 -0.2538
vn 0.4714 0.0000 -0.8819
vn -0.3264 0.0000 -0.9452
vn 0.7730 0.0000 -0.6344
vn 0.8634 0.0000 0.5045
vn 0.9569 0.0000 -0.2903
vn 0.4376 0.0000 -0.8992
vn 0.9952 0.0000 0.0980
vn 0.2538 0.0000 0.9673
vn 0.8819 0.0000 0.4714
vn 0.9452 0.0000 -0.3264
vn 0.6344 0.0000 0.7730
vn -0.5045 0.0000 0.8634
vn 0.2903 0.0000 0.9569
vn 0.8992 0.0000 0.4376
vn -0.0980 0.0000 0.9952
vn -0.9673 0.0000 0.2538
vn -0.4714 0.0000 0.8819
vn 0.3264 0.0000 0.9452
vn -0.7730 0.0000 0.6344
vn -0.8634 0.0000 -0.5045
vn -0.9569 0.0000 0.2903
vn -0.4376 0.0000 0.8992
vn -0.9952 0.0000 -0.0980
vn -0.2538 0.0000 -0.9673
vn -0.8819 0.0000 -0.4714
vn -0.9452 0.0000 0.3264
vn -0.6344 0.0000 -0.7730
vn 0.5045 0.0000 -0.8634
vn -0.2903 0.0000 -0.9569
vn 0.0980 0.0000 0.9952
vn -0.2903 0.0000 0.9569
vn 0.4714 0.0000 0.8819
vn -0.6344 0.0000 0.7730
vn 0.7730 0.0000 0.6344
vn -0.8819 0.0000 0.4714
vn 0.9569 0.0000 0.2903
vn -0.9952 0.0000 0.0980
vn 0.9952 0.0000 -0.0980
vn -0.9569 0.0000 -0.2903
vn 0.8819 0.0000 -0.4714
vn -0.7730 0.0000 -0.6344
vn 0.6344 0.0000 -0.7730
vn -0.4714 0.0000 -0.8819
vn 0.2903 0.0000 -0.9569
vn -0.0980 0.0000 -0.9952
s off
f 2//1 4//1 1//1
f 16//2 28//2 29//2
f 51//2 52//2 66//2
f 67//3 1//3 66//3
f 79//4 87//4 88//4
f 111//4 112//4 121//4
f 3//5 39//5 4//5
f 101//6 40//6 39//6
f 128//7 41//7 40//7
f 127//8 42//8 41//8
f 126//9 43//9 42//9
f 125//10 5//10 43//10
f 124//11 6//11 5//11
f 123//12 7//12 6//12
f 122//13 8//13 7//13
f 121//14 9//14 8//14
f 120//15 10//15 9//15
f 119//16 11//16 10//16
f 118//17 12//17 11//17
f 117//18 13//18 12//18
f 83//19 14//19 13//19
f 82//20 15//20 14//20
f 81//21 16//21 15//21
f 80//22 17//22 16//22
f 79//23 18//23 17//23
f 78//24 19//24 18//24
f 77//25 20//25 19//25
f 76//26 21//26 20//26
f 75//27 59//27 21//27
f 74//28 60//28 59//28
f 73//29 61//29 60//29
f 72//30 62//30 61//30
f 71//31 63//31 62//31
f 70//32 64//32 63//32
f 69//33 65//33 64//33
f 68//34 66//34 65//34
f 50//20 100//20 51//20
f 51//35 99//35 52//35
f 49//36 102//36 50//36
f 52//18 98//18 53//18
f 48//22 103//22 49//22
f 53//37 97//37 54//37
f 47//38 104//38 48//38
f 54//16 96//16 55//16
f 46//24 105//24 47//24
f 55//39 95//39 56//39
f 45//40 106//40 46//40
f 56//14 94//14 57//14
f 44//26 107//26 45//26
f 57//41 93//41 58//41
f 38//42 108//42 44//42
f 58//12 92//12 22//12
f 37//28 109//28 38//28
f 22//43 91//43 23//43
f 36//44 110//44 37//44
f 23//10 90//10 24//10
f 35//30 111//30 36//30
f 24//45 89//45 25//45
f 34//46 112//46 35//46
f 25//8 88//8 26//8
f 33//32 113//32 34//32
f 26//47 87//47 27//47
f 32//48 114//48 33//48
f 27//6 86//6 28//6
f 31//34 115//34 32//34
f 28//49 85//49 29//49
f 30//50 116//50 31//50
f 29//1 84//1 30//1
f 2//1 3//1 4//1
f 38//2 5//2 37//2
f 6//2 7//2 8//2
f 9//2 10//2 12//2
f 5//2 6//2 8//2
f 10//2 11//2 12//2
f 5//2 8//2 37//2
f 37//2 8//2 36//2
f 35//2 36//2 8//2
f 13//2 14//2 16//2
f 14//2 15//2 16//2
f 9//2 35//2 8//2
f 9//2 34//2 35//2
f 13//2 16//2 29//2
f 17//2 18//2 19//2
f 20//2 21//2 24//2
f 17//2 19//2 20//2
f 9//2 33//2 34//2
f 9//2 12//2 33//2
f 16//2 17//2 27//2
f 21//2 22//2 23//2
f 21//2 23//2 24//2
f 33//2 12//2 32//2
f 32//2 12//2 31//2
f 20//2 24//2 25//2
f 20//2 25//2 26//2
f 31//2 12//2 13//2
f 30//2 31//2 13//2
f 17//2 20//2 26//2
f 17//2 26//2 27//2
f 29//2 30//2 13//2
f 16//2 27//2 28//2
f 66//2 1//2 4//2
f 66//2 4//2 39//2
f 63//2 64//2 65//2
f 65//2 66//2 53//2
f 40//2 41//2 42//2
f 66//2 39//2 51//2
f 62//2 63//2 65//2
f 59//2 60//2 61//2
f 61//2 57//2 58//2
f 39//2 40//2 49//2
f 43//2 5//2 44//2
f 40//2 42//2 43//2
f 59//2 61//2 21//2
f 22//2 61//2 58//2
f 22//2 21//2 61//2
f 5//2 38//2 44//2
f 43//2 44//2 45//2
f 61//2 62//2 57//2
f 57//2 62//2 56//2
f 43//2 45//2 46//2
f 43//2 46//2 40//2
f 56//2 62//2 55//2
f 55//2 62//2 65//2
f 40//2 46//2 47//2
f 40//2 47//2 48//2
f 54//2 55//2 65//2
f 53//2 54//2 65//2
f 40//2 48//2 49//2
f 39//2 49//2 50//2
f 52//2 53//2 66//2
f 39//2 50//2 51//2
f 67//3 2//3 1//3
f 3//4 2//4 67//4
f 68//4 69//4 71//4
f 101//4 3//4 67//4
f 69//4 70//4 71//4
f 101//4 67//4 100//4
f 99//4 100//4 67//4
f 98//4 99//4 67//4
f 67//4 68//4 98//4
f 72//4 73//4 74//4
f 68//4 71//4 96//4
f 97//4 98//4 68//4
f 96//4 97//4 68//4
f 71//4 95//4 96//4
f 72//4 74//4 75//4
f 71//4 94//4 95//4
f 76//4 77//4 79//4
f 72//4 94//4 71//4
f 72//4 93//4 94//4
f 77//4 78//4 79//4
f 80//4 81//4 82//4
f 76//4 79//4 88//4
f 72//4 92//4 93//4
f 72//4 75//4 92//4
f 79//4 80//4 87//4
f 82//4 83//4 80//4
f 83//4 84//4 85//4
f 92//4 75//4 91//4
f 91//4 75//4 90//4
f 80//4 83//4 85//4
f 80//4 85//4 86//4
f 90//4 75//4 76//4
f 89//4 90//4 76//4
f 80//4 86//4 87//4
f 88//4 89//4 76//4
f 128//4 101//4 103//4
f 101//4 100//4 102//4
f 126//4 127//4 125//4
f 125//4 127//4 128//4
f 101//4 102//4 103//4
f 128//4 103//4 104//4
f 124//4 125//4 108//4
f 122//4 123//4 121//4
f 121//4 123//4 124//4
f 125//4 128//4 106//4
f 128//4 104//4 105//4
f 120//4 121//4 112//4
f 118//4 119//4 117//4
f 84//4 83//4 116//4
f 117//4 119//4 120//4
f 128//4 105//4 106//4
f 125//4 106//4 107//4
f 117//4 120//4 114//4
f 116//4 83//4 117//4
f 115//4 116//4 117//4
f 125//4 107//4 108//4
f 124//4 108//4 109//4
f 114//4 115//4 117//4
f 113//4 114//4 120//4
f 121//4 124//4 110//4
f 124//4 109//4 110//4
f 112//4 113//4 120//4
f 121//4 110//4 111//4
f 3//5 101//5 39//5
f 101//6 128//6 40//6
f 128//7 127//7 41//7
f 127//8 126//8 42//8
f 126//9 125//9 43//9
f 125//10 124//10 5//10
f 124//11 123//11 6//11
f 123//12 122//12 7//12
f 122//13 121//13 8//13
f 121//14 120//14 9//14
f 120//15 119//15 10//15
f 119//16 118//16 11//16
f 118//17 117//17 12//17
f 117//18 83//18 13//18
f 83//19 82//19 14//19
f 82//20 81//20 15//20
f 81//21 80//21 16//21
f 80//22 79//22 17//22
f 79//23 78//23 18//23
f 78//24 77//24 19//24
f 77//25 76//25 20//25
f 76//26 75//26 21//26
f 75//27 74//27 59//27
f 74//28 73//28 60//28
f 73//29 72//29 61//29
f 72//30 71//30 62//30
f 71//31 70//31 63//31
f 70//32 69//32 64//32
f 69//33 68//33 65//33
f 68//34 67//34 66//34
f 50//20 102//20 100//20
f 51//35 100//35 99//35
f 49//36 103//36 102//36
f 52//18 99//18 98//18
f 48//22 104//22 103//22
f 53//37 98//37 97//37
f 47//38 105//38 104//38
f 54//16 97//16 96//16
f 46//24 106//24 105//24
f 55//39 96//39 95//39
f 45//40 107//40 106//40
f 56//14 95//14 94//14
f 44//26 108//26 107//26
f 57//41 94//41 93//41
f 38//42 109//42 108//42
f 58//12 93//12 92//12
f 37//28 110//28 109//28
f 22//43 92//43 91//43
f 36//44 111//44 110//44
f 23//10 91//10 90//10
f 35//30 112//30 111//30
f 24//45 90//45 89//45
f 34//46 113//46 112//46
f 25//8 89//8 88//8
f 33//32 114//32 113//32
f 26//47 88//47 87//47
f 32//48 115//48 114//48
f 27//6 87//6 86//6
f 31//34 116//34 115//34
f 28//49 86//49 85//49
f 30//50 84//50 116//50
f 29//1 85//1 84//1
I'm going to say that glNormalPointer(GL_FLOAT, sizeof(float) * 4,normals); is causing your problems. First off, you only have 3 components in your normals, not four. I bet this is causing glDrawArrays to access out of bounds memory.
Also, because your normals are not walked correctly you could be getting garbage and it would cause some flickering.
Because your normals are tightly packed, just use 0 for the stride.

OCaml swapping elements in a list

I'm trying to swap two elements in a list, not really sure why mines not working.
The correct implementation should do the following:
list_swap_val [5;6;7;3] 75 => [7;6;5;3]
list_swap_val [5;6;3] 7 5 => [7;6;3]
Here's two different implementations I've tried but both seem to just return the original list
let rec list_swap l u v =
match l with
|[] -> []
|h::t -> if h = u then u::(list_swap t u v)
else if h = v then v::(list_swap t u v)
else h::(list_swap t u v) ;;
I also tried to do the above but with while in the match statements instead of using if, but both are not working. Where am I going wrong? Thanks for any help
You forgot to actually swap values: when you see a u, the first element of your returned list should be v. Here, it is as-if you build h::(list_swap t u v) in all cases.
By the way, you can factorize the recursive call, which gives you finally this definition:
let rec list_swap l u v =
match l with
| [] -> []
| h::t -> (if h = u then v
else if h = v then u
else h)::(list_swap t u v);;
As coredump- wrote you can factorize it, but you can go even further and notice that this is a map.
let swap u v x = if x = u then v else if x = v then u else x
let list_swap u v = List.map (swap u v)
as said above, you forgot to swap. You can also use List.map :
let swap u v n = match n with
|x when x = u -> v
|x when x = v -> u
|_ -> n;;
let list_swap l u v = List.map (swap u v) l;;
This calls the function "swap u v" (thanks to partial evaluation) on every element in the list "l".
However, this hides the recursive call and you should know map isn't tail-recursive. If you want to use map and have tail recursivity :
let list_swap l u v = List.rev (List.rev_map swap (u v) l);;
"rev_map" is the same as "map" except it reverses the list at the same time, and it is tail recursive. So you reverse the list once again afterwards. "rev" is also tail recursive !

Extracting words from a file in C

Could anyone help me to correct the following code. I
need to extract words (sequence of non white space characters up to a white space character or a new line character). Here the code prints each letter of extracted word 3 times.
#include<stdio.h>
#include<string.h>
main()
{
FILE *fp1,*fp2,*fp3;
char ch,str[10],lab[10],opc[10],opd[10];
int i;
fp1=fopen("ma.dat","r");
while((ch = fgetc(fp1)) != EOF)
{
i=0;
if(ch!=' ' || '\n' || -1)
{
lab[i++]=ch;
}
lab[i]='\0';
i=0;
if(ch!=' ' || '\n' || -1)
{
opc[i++]=ch;
}
opc[i]='\0';
i=0;
if(ch!=' ' || '\n' || -1)
{
opd[i++]=ch;
}
opd[i]='\0';
printf("%s %s %s ",lab,opc,opd);
}
fcloseall();
}
and here is my input :
copy start 1000
lda alpha
lda five
sta six
six word 4
alpha rword 5
five byte c'eof'
end
and the output is :
c c c o o o p p p y y y s s s t t t a a a r r r t t t 1 1 1 0 0 0 0 0 0 0 0 0
l l l d d d a a a a a a l l l p p p h h h a a a
l l l d d d a a a f f f i i i v v v e e e
s s s t t t a a a s s s i i i x x x
s s s i i i x x x w w w o o o r r r d d d 4 4 4
a a a l l l p p p h h h a a a r r r w w w o o o r r r d d d 5 5 5
f f f i i i v v v e e e b b b y y y t t t e e e c c c ' ' ' e e e o o o f f f ' ' '
e e e n n n d d d
Here I used the logic that scan until eof reached and (tried) to get get separate words until some space or newline is reached.
Do you have a debugger? Set a breakpoint and step through the program, line by line. You'll find that there is at least one statement in your loop that makes no sense. Hint: Why do you have the i=0 statement there inside the loop?
If this isn't just a typo after too many days of coding, you may want to read up on how
A while loop works. Especially which commands get repeated.
If works. Especially the difference between conditional statements like "if" and loop statements like "while".
PS - I'm obviously biased, but if you're looking for a good C tutorial, try my C tutorial http://masters-of-the-void.com - It's written for the Mac, but you already have your compiler up and running and you've compiled your own programs with it, so just doing the samples on Linux should be well within your skills.